Re: [PATCH -mm -v6 5/9] mm, THP, swap: Support to clear SWAP_HAS_CACHE for huge page

From: Huang\, Ying
Date: Tue Mar 14 2017 - 20:54:54 EST


Tim Chen <tim.c.chen@xxxxxxxxxxxxxxx> writes:

> On Wed, 2017-03-08 at 15:26 +0800, Huang, Ying wrote:
>> From: Huang Ying <ying.huang@xxxxxxxxx>
>>
>> __swapcache_free() is added to support to clear the SWAP_HAS_CACHE flag
>> for the huge page.ÂÂThis will free the specified swap cluster now.
>> Because now this function will be called only in the error path to free
>> the swap cluster just allocated.ÂÂSo the corresponding swap_map[i] ==
>> SWAP_HAS_CACHE, that is, the swap count is 0.ÂÂThis makes the
>> implementation simpler than that of the ordinary swap entry.
>>
>> This will be used for delaying splitting THP (Transparent Huge Page)
>> during swapping out.ÂÂWhere for one THP to swap out, we will allocate a
>> swap cluster, add the THP into the swap cache, then split the THP.ÂÂIf
>> anything fails after allocating the swap cluster and before splitting
>> the THP successfully, the swapcache_free_trans_huge() will be used to
>> free the swap space allocated.
>>
>> Cc: Andrea Arcangeli <aarcange@xxxxxxxxxx>
>> Cc: Kirill A. Shutemov <kirill.shutemov@xxxxxxxxxxxxxxx>
>> Cc: Hugh Dickins <hughd@xxxxxxxxxx>
>> Cc: Shaohua Li <shli@xxxxxxxxxx>
>> Cc: Minchan Kim <minchan@xxxxxxxxxx>
>> Cc: Rik van Riel <riel@xxxxxxxxxx>
>> Signed-off-by: "Huang, Ying" <ying.huang@xxxxxxxxx>
>> ---
>> Âinclude/linux/swap.h |ÂÂ9 +++++++--
>> Âmm/swapfile.cÂÂÂÂÂÂÂÂ| 34 ++++++++++++++++++++++++++++++++--
>> Â2 files changed, 39 insertions(+), 4 deletions(-)
>>
>> diff --git a/include/linux/swap.h b/include/linux/swap.h
>> index e3a7609a8989..2f2a6c0363aa 100644
>> --- a/include/linux/swap.h
>> +++ b/include/linux/swap.h
>> @@ -394,7 +394,7 @@ extern void swap_shmem_alloc(swp_entry_t);
>> Âextern int swap_duplicate(swp_entry_t);
>> Âextern int swapcache_prepare(swp_entry_t);
>> Âextern void swap_free(swp_entry_t);
>> -extern void swapcache_free(swp_entry_t);
>> +extern void __swapcache_free(swp_entry_t entry, bool huge);
>> Âextern void swapcache_free_entries(swp_entry_t *entries, int n);
>> Âextern int free_swap_and_cache(swp_entry_t);
>> Âextern int swap_type_of(dev_t, sector_t, struct block_device **);
>> @@ -456,7 +456,7 @@ static inline void swap_free(swp_entry_t swp)
>> Â{
>> Â}
>> Â
>> -static inline void swapcache_free(swp_entry_t swp)
>> +static inline void __swapcache_free(swp_entry_t swp, bool huge)
>> Â{
>> Â}
>> Â
>> @@ -544,6 +544,11 @@ static inline swp_entry_t get_huge_swap_page(void)
>> Â}
>> Â#endif
>> Â
>> +static inline void swapcache_free(swp_entry_t entry)
>> +{
>> + __swapcache_free(entry, false);
>> +}
>> +
>> Â#ifdef CONFIG_MEMCG
>> Âstatic inline int mem_cgroup_swappiness(struct mem_cgroup *memcg)
>> Â{
>> diff --git a/mm/swapfile.c b/mm/swapfile.c
>> index 7241c937e52b..6019f94afbaf 100644
>> --- a/mm/swapfile.c
>> +++ b/mm/swapfile.c
>> @@ -855,6 +855,29 @@ static void swap_free_huge_cluster(struct swap_info_struct *si,
>> Â _swap_entry_free(si, offset, true);
>> Â}
>> Â
>> +static void swapcache_free_trans_huge(struct swap_info_struct *si,
>> + ÂÂÂÂÂÂswp_entry_t entry)
>> +{
>> + unsigned long offset = swp_offset(entry);
>> + unsigned long idx = offset / SWAPFILE_CLUSTER;
>> + struct swap_cluster_info *ci;
>> + unsigned char *map;
>> + unsigned int i;
>> +
>> + spin_lock(&si->lock);
>> + ci = lock_cluster(si, offset);
>> + map = si->swap_map + offset;
>> + for (i = 0; i < SWAPFILE_CLUSTER; i++) {
>> + VM_BUG_ON(map[i] != SWAP_HAS_CACHE);
>> + map[i] &= ~SWAP_HAS_CACHE;
>
> Nitpicking a bit:
> map[i] = 0 Âis more readable if map[i] == SWAP_HAS_CACHE here.

OK. I will change this.

Best Regards,
Huang, Ying