Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3933625ybb; Mon, 23 Mar 2020 10:19:56 -0700 (PDT) X-Google-Smtp-Source: ADFU+vttTMofJjWFBt8YAEZiCOiJk/c7417zHBleyEzEKUu8+oLsuOGu5d/p292ZqSkU/gvhU8mP X-Received: by 2002:aca:c488:: with SMTP id u130mr304489oif.154.1584983996054; Mon, 23 Mar 2020 10:19:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584983996; cv=none; d=google.com; s=arc-20160816; b=cEZSbyJpw6urM3dkChbRz884Ba1+46Qe+7ylHu54PCLRDpM2SWP6V4ocMWroMHq8HU ieSUz3lxtKOczfLGbOFJuxsPoJM/+5IO8Z7WbhSSp+DdQR/F3HljX3YP38n65T4XGwyK UBQXPm1pAN9Byxro+WciApvYKwJh2KPcsycU3zE1OzKdS18rrpWwGE+MOG0NUxfw0VC1 sqQCGaOdiCP0kNnuspv49RWtavNiiMthFZ0SJmZYySGiIyASe0iEKk6i313gOO6GXxMl yNIZeoFNOEbwUzj9FhCW/4ZNw2bLdt+TAPtQ+4NWR4f46bCjQOKjAT2nmmFbXQWlQm/w Ldhg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :dkim-signature; bh=5UPSbpkPmie9GnveloVGF9xAODR3WB+FmPL6STYIGmc=; b=qqSrUFh8MHPa843XC3a7498A8/yeq7K5EKZb16lXKHfO+yLpC0ok/ZyKqkIiRYHyUl WCKGlYPYkKTx7TSS4/ZFD2+3Wmv6GgFwoCooxyiDpVihB/KWwGWA6Np15M3Cn5P823Sl zSxiTs8lua2G+kAL/EwRN1wGxkLmE4r1QrO84uNkV1Vo49mCDWFZAg8obWV7ulCdDJqw Kqb7wvNZmsxQfYKK7j5DLhFD1Epf6qzeI3ddRTP2X7pFbCPhNSQ5/xlMwLdjZkZyPjn4 KSQxF0N1FnNHntmMvOVdUmhguacpRv2CaR8BogKrYrhc1BiYgTua4Xo3sxO1H8R4w7xC 6hJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=TeUavIPY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n5si309552oof.46.2020.03.23.10.19.43; Mon, 23 Mar 2020 10:19:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=TeUavIPY; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=cmpxchg.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727841AbgCWRRs (ORCPT + 99 others); Mon, 23 Mar 2020 13:17:48 -0400 Received: from mail-qt1-f193.google.com ([209.85.160.193]:42368 "EHLO mail-qt1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727650AbgCWRRr (ORCPT ); Mon, 23 Mar 2020 13:17:47 -0400 Received: by mail-qt1-f193.google.com with SMTP id t9so8396630qto.9 for ; Mon, 23 Mar 2020 10:17:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=5UPSbpkPmie9GnveloVGF9xAODR3WB+FmPL6STYIGmc=; b=TeUavIPYFPLLqG/YaNLT3tjSeohe+zeYsi+/hQqhjeL3hrswyeziREW5u6eRWYe4Ni kJASgeDjr2RVDtA9njTLtIeOWrdov4NpKmJmkWL7HBL2Ra0gqpGNrXV3KUj73gFgzCd9 /OIxrBwjc0Blky9EdkhAKHS8kvVkpJSpFdZayB18qCSAzPCjhAn7VGgsTbtTUdR/rTjE /CqgIMZhscCPLFSLFr10JPMzAFzgpFiHg4gB7VJaOI82SxNYm/8EjtfpkGyT0W5CPxIH 4Ud0euudcDhHcIFCE//XhdDxajDBWjq84tN/HZBhultz48iEt79YEdP4Trpjbt2izzPi UHJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=5UPSbpkPmie9GnveloVGF9xAODR3WB+FmPL6STYIGmc=; b=VEiWDvCunUlVL0scdtWrxi6qYpyfsba3z4qUZ3h0JyoZouPC9MIbCz5autVCgmbOES cnMe7fetw6NzwRKCK4gALNtCiiMydt1ZFK3VKzIex36fxqkDIZOuIGMIZytvQi9J8QuU GD4BnwnE3UGqEOpPInJxSDmHLuXZi4eHPfh1RoYVvFlDy9zguPBu/AzwjqFQX6DP1byY C+kqqDTaOmVk98iYHuaergixC9TQawR1GlcH4OJCXFoqMTMn2yDtlb9iqzzXljVBiNX6 Knq/RUdc06xMm4A+Fw7rS8xhAVf52kq0nxpi/i4/Mwbu91wuoP+8+ejA5nYPe2MQw6qb iNQA== X-Gm-Message-State: ANhLgQ0wCTjW6CO83OezatmtxtzGOeBM8C0ckEOxt17wygsDruObKe/G LndGdDxCdUPWrt/dFJQkIYMblg== X-Received: by 2002:ac8:4e24:: with SMTP id d4mr22504101qtw.307.1584983866330; Mon, 23 Mar 2020 10:17:46 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:a9a9]) by smtp.gmail.com with ESMTPSA id v126sm11586447qkb.107.2020.03.23.10.17.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 Mar 2020 10:17:45 -0700 (PDT) Date: Mon, 23 Mar 2020 13:17:44 -0400 From: Johannes Weiner To: js1304@gmail.com Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Michal Hocko , Hugh Dickins , Minchan Kim , Vlastimil Babka , Mel Gorman , kernel-team@lge.com, Joonsoo Kim Subject: Re: [PATCH v4 6/8] mm/swap: implement workingset detection for anonymous LRU Message-ID: <20200323171744.GD204561@cmpxchg.org> References: <1584942732-2184-1-git-send-email-iamjoonsoo.kim@lge.com> <1584942732-2184-7-git-send-email-iamjoonsoo.kim@lge.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1584942732-2184-7-git-send-email-iamjoonsoo.kim@lge.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Mar 23, 2020 at 02:52:10PM +0900, js1304@gmail.com wrote: > From: Joonsoo Kim > > This patch implements workingset detection for anonymous LRU. > All the infrastructure is implemented by the previous patches so this patch > just activates the workingset detection by installing/retrieving > the shadow entry. > > Signed-off-by: Joonsoo Kim > --- > include/linux/swap.h | 6 ++++++ > mm/memory.c | 7 ++++++- > mm/swap_state.c | 20 ++++++++++++++++++-- > mm/vmscan.c | 7 +++++-- > 4 files changed, 35 insertions(+), 5 deletions(-) > > diff --git a/include/linux/swap.h b/include/linux/swap.h > index 273de48..fb4772e 100644 > --- a/include/linux/swap.h > +++ b/include/linux/swap.h > @@ -408,6 +408,7 @@ extern struct address_space *swapper_spaces[]; > extern unsigned long total_swapcache_pages(void); > extern void show_swap_cache_info(void); > extern int add_to_swap(struct page *page); > +extern void *get_shadow_from_swap_cache(swp_entry_t entry); > extern int add_to_swap_cache(struct page *page, swp_entry_t entry, > gfp_t gfp, void **shadowp); > extern int __add_to_swap_cache(struct page *page, swp_entry_t entry); > @@ -566,6 +567,11 @@ static inline int add_to_swap(struct page *page) > return 0; > } > > +static inline void *get_shadow_from_swap_cache(swp_entry_t entry) > +{ > + return NULL; > +} > + > static inline int add_to_swap_cache(struct page *page, swp_entry_t entry, > gfp_t gfp_mask, void **shadowp) > { > diff --git a/mm/memory.c b/mm/memory.c > index 5f7813a..91a2097 100644 > --- a/mm/memory.c > +++ b/mm/memory.c > @@ -2925,10 +2925,15 @@ vm_fault_t do_swap_page(struct vm_fault *vmf) > page = alloc_page_vma(GFP_HIGHUSER_MOVABLE, vma, > vmf->address); > if (page) { > + void *shadow; > + > __SetPageLocked(page); > __SetPageSwapBacked(page); > set_page_private(page, entry.val); > - lru_cache_add_anon(page); > + shadow = get_shadow_from_swap_cache(entry); > + if (shadow) > + workingset_refault(page, shadow); Hm, this is calling workingset_refault() on a page that isn't charged to a cgroup yet. That means the refault stats and inactive age counter will be bumped incorrectly in the root cgroup instead of the real one. > + lru_cache_add(page); > swap_readpage(page, true); > } > } else { You need to look up and remember the shadow entry at the top and call workingset_refault() after mem_cgroup_commit_charge() has run. It'd be nice if we could do the shadow lookup for everybody in lookup_swap_cache(), but that's subject to race conditions if multiple faults on the same swap page happen in multiple vmas concurrently. The swapcache bypass scenario is only safe because it checks that there is a single pte under the mmap sem to prevent forking. So it looks like you have to bubble up the shadow entry through swapin_readahead().