From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-9.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B77F3C433E1 for ; Wed, 20 May 2020 23:26:13 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 715BC20897 for ; Wed, 20 May 2020 23:26:13 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=cmpxchg-org.20150623.gappssmtp.com header.i=@cmpxchg-org.20150623.gappssmtp.com header.b="Fz6dmISB" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 715BC20897 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=cmpxchg.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id D50D08000D; Wed, 20 May 2020 19:26:09 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D05DE8000A; Wed, 20 May 2020 19:26:09 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B80688000D; Wed, 20 May 2020 19:26:09 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0083.hostedemail.com [216.40.44.83]) by kanga.kvack.org (Postfix) with ESMTP id 9826B8000A for ; Wed, 20 May 2020 19:26:09 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 531A1180AD81A for ; Wed, 20 May 2020 23:26:09 +0000 (UTC) X-FDA: 76838682858.17.fall57_189ab6cec4821 X-HE-Tag: fall57_189ab6cec4821 X-Filterd-Recvd-Size: 6019 Received: from mail-qk1-f194.google.com (mail-qk1-f194.google.com [209.85.222.194]) by imf10.hostedemail.com (Postfix) with ESMTP for ; Wed, 20 May 2020 23:26:08 +0000 (UTC) Received: by mail-qk1-f194.google.com with SMTP id 190so5555175qki.1 for ; Wed, 20 May 2020 16:26:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cmpxchg-org.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=HJDfvKd/xQ+U/A8BiqznBlIOAX4alsApJfZU8rh9CnI=; b=Fz6dmISBeqccLp92SIXlWpZ4Azk3J/vmLzFY5xmcQlxADIPoHHlyHraLVAj7OZUKVp n3BskcozIV7s77yj6cNgbDIZni1VpzH871u2OMtUJXOOmAHgFtjBsBG0UFMjJRBJupvC Yz5A9ODIDyk5meuBLYNJ5wk/syTQIMSwrII92tLUyMni08y2bsn59zRkQGqhiZdZHyvA wibKQvsMqsubKVxJ4Xn53Wz6L/XBKMlWCs/peKgGpGu2sLdIaDzkpgLcBysyBP7RqTu1 PUFqqHOtLdaL7yYc+m6Qc+PlYM91ZKwumkyvKsNL8e3t2TFpfyfMfX5SYHtuwf7ee0xA yd/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HJDfvKd/xQ+U/A8BiqznBlIOAX4alsApJfZU8rh9CnI=; b=bbji61MhnhmmPze/etIMrJ71LQYX+kacjn9B9C/cR0WzBqVLS1eiRoBOACQOqHYKUM oP9tXwgvqa8K2eqpIRKuzvWbnvoCexvO46q+RhtsWjtMsZGHO4vOJmsTjzcUtQtocQ17 XQd/B0aZClnqi7kdle0+9FgZGluAdmqerFkhvzAqkRZ7R/c6bsYuY7hXERe1i5gq6gO0 uKBOfeZiGKGLZU1nMeuoB2WpK6l66nGVokCyhRD/bJV8sld4DwQoeWMiEORX1QrMDvgm bS8St6k4HoM59+xattnAIToVzRTY+JWUdbrHiuLEiJ1Saa+YCjXWVA/SNxsryf7VDQ+n emEQ== X-Gm-Message-State: AOAM533/G1LrE4WG1s2cv6J59c4+mgoMGiO96wjw1XE1tDoXyp5naHxb eY2OLnYYKfBYBcjLwcFlis1aJZD2qss= X-Google-Smtp-Source: ABdhPJxoMydyCn7v1MWAcLb23MBY3YgxIiym2FF8pOGzEVh285Tr6htPKp/YVFywnRRUF3nRDo/cLA== X-Received: by 2002:ae9:e404:: with SMTP id q4mr7364353qkc.129.1590017167920; Wed, 20 May 2020 16:26:07 -0700 (PDT) Received: from localhost ([2620:10d:c091:480::1:4708]) by smtp.gmail.com with ESMTPSA id o3sm3596698qtt.56.2020.05.20.16.26.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 May 2020 16:26:07 -0700 (PDT) From: Johannes Weiner To: linux-mm@kvack.org Cc: Rik van Riel , Minchan Kim , Michal Hocko , Andrew Morton , Joonsoo Kim , linux-kernel@vger.kernel.org, kernel-team@fb.com Subject: [PATCH 05/14] mm: workingset: let cache workingset challenge anon Date: Wed, 20 May 2020 19:25:16 -0400 Message-Id: <20200520232525.798933-6-hannes@cmpxchg.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200520232525.798933-1-hannes@cmpxchg.org> References: <20200520232525.798933-1-hannes@cmpxchg.org> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: We activate cache refaults with reuse distances in pages smaller than the size of the total cache. This allows new pages with competitive access frequencies to establish themselves, as well as challenge and potentially displace pages on the active list that have gone cold. However, that assumes that active cache can only replace other active cache in a competition for the hottest memory. This is not a great default assumption. The page cache might be thrashing while there are enough completely cold and unused anonymous pages sitting around that we'd only have to write to swap once to stop all IO from the cache. Activate cache refaults when their reuse distance in pages is smaller than the total userspace workingset, including anonymous pages. Reclaim can still decide how to balance pressure among the two LRUs depending on the IO situation. Rotational drives will prefer avoiding random IO from swap and go harder after cache. But fundamentally, hot cache should be able to compete with anon pages for a place in RAM. Signed-off-by: Johannes Weiner --- mm/workingset.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/mm/workingset.c b/mm/workingset.c index 474186b76ced..e69865739539 100644 --- a/mm/workingset.c +++ b/mm/workingset.c @@ -277,8 +277,8 @@ void workingset_refault(struct page *page, void *shad= ow) struct mem_cgroup *eviction_memcg; struct lruvec *eviction_lruvec; unsigned long refault_distance; + unsigned long workingset_size; struct pglist_data *pgdat; - unsigned long active_file; struct mem_cgroup *memcg; unsigned long eviction; struct lruvec *lruvec; @@ -310,7 +310,6 @@ void workingset_refault(struct page *page, void *shad= ow) goto out; eviction_lruvec =3D mem_cgroup_lruvec(eviction_memcg, pgdat); refault =3D atomic_long_read(&eviction_lruvec->inactive_age); - active_file =3D lruvec_page_state(eviction_lruvec, NR_ACTIVE_FILE); =20 /* * Calculate the refault distance @@ -345,10 +344,18 @@ void workingset_refault(struct page *page, void *sh= adow) =20 /* * Compare the distance to the existing workingset size. We - * don't act on pages that couldn't stay resident even if all - * the memory was available to the page cache. + * don't activate pages that couldn't stay resident even if + * all the memory was available to the page cache. Whether + * cache can compete with anon or not depends on having swap. */ - if (refault_distance > active_file) + workingset_size =3D lruvec_page_state(eviction_lruvec, NR_ACTIVE_FILE); + if (mem_cgroup_get_nr_swap_pages(memcg) > 0) { + workingset_size +=3D lruvec_page_state(eviction_lruvec, + NR_INACTIVE_ANON); + workingset_size +=3D lruvec_page_state(eviction_lruvec, + NR_ACTIVE_ANON); + } + if (refault_distance > workingset_size) goto out; =20 SetPageActive(page); --=20 2.26.2