Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp945198ybk; Wed, 20 May 2020 16:31:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwOgmSo2Y+9r99tXmtH4IADIJ1Kx0rho2yApuPdhJdDUpJ88RcgRQqn7rPqC4/QxTsMaO8k X-Received: by 2002:a17:906:90d4:: with SMTP id v20mr1311080ejw.387.1590017481035; Wed, 20 May 2020 16:31:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1590017481; cv=none; d=google.com; s=arc-20160816; b=aIVBuhZwz3f6j74BkXCNSZYaX5+vgkHiVBIvnjuUXbXTQuQTCR1NssgdViCy5YbS/8 uedkHYDfTPEAsT5O2AFWZa52/ucxZI9Worgp5dz3NdJyZucfYyJufajTUU+jm09vDTFS 543jLxwaaix7zuBNDHWtQ9R133eXkk/lpE4kwUNdK1JUu6UB9iBwIHcWc622gXpbbJyS EiTcxYwp/iQa9OKpej81KiaSZqwa6+CgWbUgWYsJh4vo/nMWe+ZGnVcZU1SGkfxzpf8Z KKuJ9Vh9WdqLppjSLRPrGVNik2bzp50iDKw2srB7+g6nbbOutMt4WH1B5ayBAY15HYLN vVBg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=HJDfvKd/xQ+U/A8BiqznBlIOAX4alsApJfZU8rh9CnI=; b=YpRs7QMFq0ukrU+iZbhaja8fox2AkaZHXk0b2QVPgl2/VspslyR6wK6sXNUkrNdDNn S4aOrHaWJb4Gc0XsvTEsIMnOWW0PTjtcvfdT/Mopbk+eICgNovSwG3Pmi11SBnrapUkj Nfmo6Ec/Lf1FNtT1inLIg4ap7qUEwfSAJnp/IWBu+sSSPRDYveEnPwskXA2G6DorbnCx +iZ07Ostss2KS1/R+YZ1zrENxPIQrsBctcBiOSbJp8IuYbKQ5SQDAFD8WQx5t41bGuE/ lEDz6Rp0q+bglJS0eiTUkHPcBxylSEwuRY/IL7ZW1iqC8w6D2oqIc4rNXvpnH8xQVsHK bsvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=Fz6dmISB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id f13si2332796edc.577.2020.05.20.16.30.58; Wed, 20 May 2020 16:31:21 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@cmpxchg-org.20150623.gappssmtp.com header.s=20150623 header.b=Fz6dmISB; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1728784AbgETX0K (ORCPT + 99 others); Wed, 20 May 2020 19:26:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55678 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728462AbgETX0I (ORCPT ); Wed, 20 May 2020 19:26:08 -0400 Received: from mail-qk1-x743.google.com (mail-qk1-x743.google.com [IPv6:2607:f8b0:4864:20::743]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A09DFC061A0E for ; Wed, 20 May 2020 16:26:08 -0700 (PDT) Received: by mail-qk1-x743.google.com with SMTP id f13so5535044qkh.2 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=FwsfTnbvrBK0r5U72E+pBnMB9rqmRamyCS46CYyEuB7Zk43Pk085LprMA0HEpeSur4 0b+mHl5PS/7IDMUxfqE3O7upBC9Gdq0Qhple/xQeD+naoLI025bOXI33o5eVJM0fKm8N 3rXCdafx7IgO/dlxOmJHPCO9HygKgoHePS9QOqGmCuyLgLjZWzj/rBqYHPY/6YXbf4Ko wI8jIT4z88IoQaF6nZRiWJsbldxWpPyqMasr6Pp9CUT/qbTX/EiQviTbixtwwyGIdv0P sI/szyrP8A0wruIQ2tvHdzIVogjHFxyNzEjFC90bO9qNm5SWFEmsCB/t+ABp1k7ndOxt awgw== X-Gm-Message-State: AOAM530VpTYS8IdxICTu5G2yOa2Uyw2q628fwkdm3P+jGxNacKJmXZtc E0D3bwzMACMvJu7pRx2QOh+UxA4Eb/c= 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: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 *shadow) 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 *shadow) goto out; eviction_lruvec = mem_cgroup_lruvec(eviction_memcg, pgdat); refault = atomic_long_read(&eviction_lruvec->inactive_age); - active_file = lruvec_page_state(eviction_lruvec, NR_ACTIVE_FILE); /* * Calculate the refault distance @@ -345,10 +344,18 @@ void workingset_refault(struct page *page, void *shadow) /* * 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 = lruvec_page_state(eviction_lruvec, NR_ACTIVE_FILE); + if (mem_cgroup_get_nr_swap_pages(memcg) > 0) { + workingset_size += lruvec_page_state(eviction_lruvec, + NR_INACTIVE_ANON); + workingset_size += lruvec_page_state(eviction_lruvec, + NR_ACTIVE_ANON); + } + if (refault_distance > workingset_size) goto out; SetPageActive(page); -- 2.26.2