From patchwork Wed Feb 14 06:05:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kinsey Ho X-Patchwork-Id: 200819 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:bc8a:b0:106:860b:bbdd with SMTP id dn10csp1015691dyb; Tue, 13 Feb 2024 22:09:45 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCX51W7nWJgPKMIDC5siwYNLz9Xkvm/SxL2K/6jynghfXyOa0kOserUksqfxotMWlCJFTLLx2+cLhUmyGKqaZJdTm13i/Q== X-Google-Smtp-Source: AGHT+IHJ4xDNXXJVQExyea+53lgZiHu/n4TotmEznrf/XSX8QFkfATGybmMKRhfpY0p9OcgKV8TO X-Received: by 2002:a17:902:fc84:b0:1d9:7ebe:432a with SMTP id mf4-20020a170902fc8400b001d97ebe432amr2081602plb.30.1707890985555; Tue, 13 Feb 2024 22:09:45 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707890985; cv=pass; d=google.com; s=arc-20160816; b=n6BDHujiWFeCZtCl95yCE5MiGY60PzWhOr6ENY3ZwcNYAhuIwfeqaQQ52MZINPvo6d uM0gH70MPjRu0EMtPeMTSo30V9LbitVEf0w/EqxxQo2iDXNrrO9uqb0+XALYFidAUQQW Jrv/SPv8oBossIQHkshvPc7DIJ++oQlC5/POr9mpVZpY0G+jQyDOcF+q/N/Pl/ITa2E9 CgpxtI26SsJ/CKM7g1mYkOA32+M6jGNUpepGur1Vo7gAexlI+p/pRhdqYgztMEMAvNkZ ttcVmg5OcujOFL3jG3SxXfix3PjwSqm7tk0tVS9SaAZPRiQ5gmNvvWDnS3Hwp99YbrNP Kavw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:from:subject:message-id:references:mime-version :list-unsubscribe:list-subscribe:list-id:precedence:in-reply-to:date :dkim-signature; bh=g6dfBLL0uVL4kHNX/u5ol8tmo8iu96qepQdMS5ybNno=; fh=hex46nxWKRlprmrTs0sS3DzO5Q1xSvA2AeUfQQ+/Dy0=; b=QMsQhv4h/z56rDCnJl0S3BENDsSCAIKsBbfk6JImSpM68tsEKfqLDJQjnDeMvGYZ4l UgKp7SM+onm1tYnuQvlBzOjjoEJhzBVEuRJYSy6LigYY7anfQsrJ70aPDpg/5d8CLpNq VdnNDCEavrvADrHJEWKQt7iuM9vxEcebxi/KD14hpHear57dUTjt5fOm1kljNFEq/UHc bTY9G2zrhl/SHCwaqG+I+uVu+y4L62JzDuyiOhLqE2V5vBdjS6Z5BRBB+zEWS7WKuIXB lrP0G6bngFrdune4w/qe3X6LvjXZeSGOG1PP9FcXqW+JKbN74MIPCEAfO02vnTaeqq0q 368w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ODbChT5F; arc=pass (i=1 spf=pass spfdomain=flex--kinseyho.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64771-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64771-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com X-Forwarded-Encrypted: i=2; AJvYcCUulZcyIjeS2Obv+IQMfycxBPQsBPNal4iz52dBUAG2HqTRmJ/WDg5rQ4UHvthKGY+81viLi4xe9UGLsUA54udvkx3Sbg== Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id l13-20020a170902f68d00b001d942b506b4si3381833plg.357.2024.02.13.22.09.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 22:09:45 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-64771-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=ODbChT5F; arc=pass (i=1 spf=pass spfdomain=flex--kinseyho.bounces.google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-64771-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-64771-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id E1F2CB28DAF for ; Wed, 14 Feb 2024 06:07:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D654D1427F; Wed, 14 Feb 2024 06:06:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="ODbChT5F" Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 96D0812B6D for ; Wed, 14 Feb 2024 06:06:07 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.202 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707890769; cv=none; b=asNbTL6K9LdBsyCsjX4ULQwP8VHazOIv+1WwsMZ1aHQHzAyyi/nNmHPoZOXUmBPFMF8YWF/ETJOSB+aA5RZYmJaVMg3PYrtZ+NEcQyVDSfj5trb+ftNR96ngefjhXSgob5OSKY+IyaB19YZWavEucSOEb8K8N29bB6q7CvabrEA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707890769; c=relaxed/simple; bh=Nn2aC7Sxme7TmKC1R3Wk8wOWqMobubOZoyNWF/vBV5g=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=MrvM8HGc044mcwXBqWt63tn/P5StNmBIGPzpGIEAF4CgO82dSos7dZ7OES6hAP22fMg04cwhaz3TUXvk282WuoPRrXKLbZzMb0OoK0JBdDhWKAv3o4RpXJ8e+7RQlNOzEgOE8RList0y54BvkSVwdAZMvDDGqDV56kDxopwmegA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--kinseyho.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=ODbChT5F; arc=none smtp.client-ip=209.85.219.202 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--kinseyho.bounces.google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dc64f63d768so9592209276.2 for ; Tue, 13 Feb 2024 22:06:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1707890766; x=1708495566; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=g6dfBLL0uVL4kHNX/u5ol8tmo8iu96qepQdMS5ybNno=; b=ODbChT5FsP0oX96JxVWgtHoQT/oywaMaxAkMh76Qw8EVQmlp9DwXnYFHwnwVoDKydf 2fUspDR88SYD552K9bn3lZEF3xot/HRMYfl7xUT/KbbTxxcmQ6qZ3FjZi8LTw+HpfxAi P6qFEfmBm5OO7VXMoTXBx/RQKq8CO51DNJdlcp9A9zHz9DYPFt+EP4SsEz1xYcshw9/P Bu/TNTbzIlJUT6JR1QtMBRbcW2F9jdkMKx6XqL0krYuMHutCOYBf791CD2XxMvTKDgm+ KYv/7C3ocsfJIsu0I0HzfwMyH58rTO8FD/Hw86RWH+bgX7RzYm46IyGwWPwKXIW04SIZ DO+A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707890766; x=1708495566; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=g6dfBLL0uVL4kHNX/u5ol8tmo8iu96qepQdMS5ybNno=; b=RXznkIOI3jaFEaEad2xMZTyrhIzdl1yiFy0jzYqkS8Egii8WDAp8xJsRzHEldL1tsz 9H6mGfz6VWIuJTrN+Y/BAPIEnes6otwNozxC4klNeIvGiHCCLBhhME6Yd2vI6aLrwCSM LgLij64T/2/LQxl7DG5TPJp+L4yN1dLKg18xLLw/NGGQsgBXKT/xtS/ASJGP5ERtWQIt lLFdR8m0dXTxVqPM8h2DBiTF3PGVihuPxjoHizP6mwYTw4zjxPrID3B2mPqNpBrK80a/ +xM37u0oBeS51MLP7hJucPh1qZfn9jSgnaheHfl7YcqvGt1pdWLthCdtskhREv9g64UW 00yw== X-Forwarded-Encrypted: i=1; AJvYcCXJx+Ul59RrWqll8A+7QmYyvmkLCyAsSs/s57tD7Z6OzFyHu2RxcJ+Nsxt4HnDoFfttBkIalxIxPtv+aOZbMafKb5MKOZkprcNjdjGf X-Gm-Message-State: AOJu0YxlIH0YcntuID+LmVj/DEHMu6uelqAiP4Zs5VGA7MSUs08OxkyP /BU48jWtMuB0Ef25jWot06ISVJFI/xP3DvckydSPrT2L4Uv4ZNqlDdLkC2mDO6zI0hmQJGDD97K W+WCaZpBzJA== X-Received: from kinseyct.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:46b]) (user=kinseyho job=sendgmr) by 2002:a05:6902:1505:b0:dc6:cd85:bcd7 with SMTP id q5-20020a056902150500b00dc6cd85bcd7mr322452ybu.3.1707890766683; Tue, 13 Feb 2024 22:06:06 -0800 (PST) Date: Wed, 14 Feb 2024 06:05:38 +0000 In-Reply-To: <20240214060538.3524462-1-kinseyho@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20240214060538.3524462-1-kinseyho@google.com> X-Mailer: git-send-email 2.43.0.687.g38aa6559b0-goog Message-ID: <20240214060538.3524462-6-kinseyho@google.com> Subject: [PATCH mm-unstable v1 5/5] mm/mglru: improve swappiness handling From: Kinsey Ho To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao , Donet Tom , "Aneesh Kumar K . V" , Kinsey Ho X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790853498405810725 X-GMAIL-MSGID: 1790853498405810725 The reclaimable number of anon pages used to set initial reclaim priority is only based on get_swappiness(). Use can_reclaim_anon_pages() to include NUMA node demotion. Also move the swappiness handling of when !__GFP_IO in try_to_shrink_lruvec() into isolate_folios(). Signed-off-by: Kinsey Ho --- mm/vmscan.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index f1019afa7813..0daf932feb86 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4307,7 +4307,7 @@ static bool isolate_folio(struct lruvec *lruvec, struct folio *folio, struct sca { bool success; - /* swapping inhibited */ + /* swap constrained */ if (!(sc->gfp_mask & __GFP_IO) && (folio_test_dirty(folio) || (folio_test_anon(folio) && !folio_test_swapcache(folio)))) @@ -4476,9 +4476,11 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw DEFINE_MIN_SEQ(lruvec); /* - * Try to make the obvious choice first. When anon and file are both - * available from the same generation, interpret swappiness 1 as file - * first and MAX_SWAPPINESS as anon first. + * Try to make the obvious choice first, and if anon and file are both + * available from the same generation, + * 1. Interpret swappiness 1 as file first and MAX_SWAPPINESS as anon first. + * 2. If !__GFP_IO, file first since clean pagecache is more likely to + * exist than clean swapcache. */ if (!swappiness) type = LRU_GEN_FILE; @@ -4488,6 +4490,8 @@ static int isolate_folios(struct lruvec *lruvec, struct scan_control *sc, int sw type = LRU_GEN_FILE; else if (swappiness == MAX_SWAPPINESS) type = LRU_GEN_ANON; + else if (!(sc->gfp_mask & __GFP_IO)) + type = LRU_GEN_FILE; else type = get_type_to_scan(lruvec, swappiness, &tier); @@ -4731,10 +4735,6 @@ static bool try_to_shrink_lruvec(struct lruvec *lruvec, struct scan_control *sc) unsigned long scanned = 0; int swappiness = get_swappiness(lruvec, sc); - /* clean file folios are more likely to exist */ - if (swappiness && !(sc->gfp_mask & __GFP_IO)) - swappiness = 1; - while (true) { int delta; @@ -4897,7 +4897,6 @@ static void set_initial_priority(struct pglist_data *pgdat, struct scan_control { int priority; unsigned long reclaimable; - struct lruvec *lruvec = mem_cgroup_lruvec(NULL, pgdat); if (sc->priority != DEF_PRIORITY || sc->nr_to_reclaim < MIN_LRU_BATCH) return; @@ -4907,7 +4906,7 @@ static void set_initial_priority(struct pglist_data *pgdat, struct scan_control * where reclaimed_to_scanned_ratio = inactive / total. */ reclaimable = node_page_state(pgdat, NR_INACTIVE_FILE); - if (get_swappiness(lruvec, sc)) + if (can_reclaim_anon_pages(NULL, pgdat->node_id, sc)) reclaimable += node_page_state(pgdat, NR_INACTIVE_ANON); /* round down reclaimable and round up sc->nr_to_reclaim */