From patchwork Mon Dec 5 23:08:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: SeongJae Park X-Patchwork-Id: 29998 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2520009wrr; Mon, 5 Dec 2022 15:09:51 -0800 (PST) X-Google-Smtp-Source: AA0mqf4/wS7Ybmrb8XgHhrWkqkSmp5CSnB0zgUCiTUd0WsJ+gCMj9k7BoExLbfNmVUYVThCcNBat X-Received: by 2002:a17:902:74ca:b0:189:c9f7:fac4 with SMTP id f10-20020a17090274ca00b00189c9f7fac4mr11740148plt.151.1670281791511; Mon, 05 Dec 2022 15:09:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670281791; cv=none; d=google.com; s=arc-20160816; b=x8iwFQ94RhtifHQqyjKGupzI1JZh2s/w45oEk3WhjEoCJwM7mjblYGbpQjZJwO1/i6 VUR15fOhfhIDJTv3n/0fd+9j22XmJjRq4qxej5BaNbH+O7OttPap/xHopaUwBlT5eJ+9 FXfYDAdv67nMmzvwgapj2rULlUs8jPzUCV2UIoMwdK1kD4MuOf/sD5d8kOqBLWQs6tg/ BB7I3vXlnHX3zE9L/qRQV66mf6g/BWNDxcLIIh+KDhCp4wyvTR1MEu14nSvqCIrgrrw9 qk8lQUvazE0ReD75mXwug1a7lxTur/uPGKLtXEDGB0wPn7jF4fhydt11N7uqpO5fvv93 tu/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=CDD01R5AGR0VCKXOUvbXwSINuJd3g9aT00R1KPyCMrI=; b=vxdLFFwAxMHWBqPuwNhqv9Ky9diqcft2lpXu4mZ+2HpqOM9ppk4bF5C32I1DHAnVnm 9U4cV1UX1RvUq06OKciWvMUiCEGcGge3zyvB99Vebe6YdostOM6Wf21ImvGzeU7untyG +o7wot9GafSd9zuF8JhVVDNZ7gPTXAnYwSuRFog20GHqBHP7W/bm2BC88lSK2r1iR2tB hw0isHUnnXlag6m1W7VvUhBlo2wEXyUzGmor5ndZLdZV6Bz+jIHEGYCa9iNNm6K8fj27 1ctPipign4aB4lGrw4Ve5Vu8Yge043W9f0KhmW2KybqBcSHfGmRVFaPmiy3qlj+MqKkE SGvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OZtT+uKK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b77-20020a621b50000000b00576916b7127si7562107pfb.181.2022.12.05.15.09.37; Mon, 05 Dec 2022 15:09:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=OZtT+uKK; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232726AbiLEXJI (ORCPT + 99 others); Mon, 5 Dec 2022 18:09:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231892AbiLEXIk (ORCPT ); Mon, 5 Dec 2022 18:08:40 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 030D46544 for ; Mon, 5 Dec 2022 15:08:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A91E1B815A3 for ; Mon, 5 Dec 2022 23:08:38 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D62FDC433D6; Mon, 5 Dec 2022 23:08:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1670281717; bh=A+37s6JJXYN+1C0NX4ExPJftU7PAKfFK4zc/BA9nVsg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OZtT+uKK4/4lwOI6eMAjYSBULmKtBrpMkQl2IHAUITb7EXo98LhCroIQJT8y9r+hV RjErPSimYQk6wI+oQHnJ2W8q1HKG7VsvuN3Z+CN8V9E9/92jWWK9WujY4iRGqptbr9 dZ1X1kwT3xUlFezXuwH46XHCKBojafP0YCqEFGFR1vZNAWcV05AY87wJz86mrDFUu8 7AT3dCObaN7p4ljYZ0j2i9jOwjEn4aYoNgDh58H+HC36IVp3cySUm5RJG8jNb1gCrq Qpf8bWCAA+bJNi9KZjsPhX+0mk7H/hdAO4opS9KDOUtLyh6k3SSBP+kytCHh8F6y1J YJYBKx0ps72Uw== From: SeongJae Park To: Andrew Morton Cc: damon@lists.linux.dev, linux-mm@kvack.org, linux-kernel@vger.kernel.org, SeongJae Park Subject: [PATCH 02/11] mm/damon/paddr: support DAMOS filters Date: Mon, 5 Dec 2022 23:08:21 +0000 Message-Id: <20221205230830.144349-3-sj@kernel.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221205230830.144349-1-sj@kernel.org> References: <20221205230830.144349-1-sj@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751417400288602007?= X-GMAIL-MSGID: =?utf-8?q?1751417400288602007?= Implement support of the DAMOS filters in the physical address space monitoring operations set, for all DAMOS actions that it supports including 'pageout', 'lru_prio', and 'lru_deprio'. Signed-off-by: SeongJae Park --- mm/damon/paddr.c | 71 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 62 insertions(+), 9 deletions(-) diff --git a/mm/damon/paddr.c b/mm/damon/paddr.c index e1a4315c4be6..ebd1905eed6f 100644 --- a/mm/damon/paddr.c +++ b/mm/damon/paddr.c @@ -202,7 +202,47 @@ static unsigned int damon_pa_check_accesses(struct damon_ctx *ctx) return max_nr_accesses; } -static unsigned long damon_pa_pageout(struct damon_region *r) +static bool __damos_pa_filter_out(struct damos_filter *filter, + struct page *page) +{ + bool matched = false; + struct mem_cgroup *memcg; + + switch (filter->type) { + case DAMOS_FILTER_TYPE_ANON: + matched = PageAnon(page); + break; + case DAMOS_FILTER_TYPE_MEMCG: + rcu_read_lock(); + memcg = page_memcg_check(page); + if (!memcg) + matched = false; + else + matched = filter->memcg_id == mem_cgroup_id(memcg); + rcu_read_unlock(); + break; + default: + break; + } + + return matched == filter->matching; +} + +/* + * damos_pa_filter_out - Return true if the page should be filtered out. + */ +static bool damos_pa_filter_out(struct damos *scheme, struct page *page) +{ + struct damos_filter *filter; + + damos_for_each_filter(filter, scheme) { + if (__damos_pa_filter_out(filter, page)) + return true; + } + return false; +} + +static unsigned long damon_pa_pageout(struct damon_region *r, struct damos *s) { unsigned long addr, applied; LIST_HEAD(page_list); @@ -213,6 +253,11 @@ static unsigned long damon_pa_pageout(struct damon_region *r) if (!page) continue; + if (damos_pa_filter_out(s, page)) { + put_page(page); + continue; + } + ClearPageReferenced(page); test_and_clear_page_young(page); if (isolate_lru_page(page)) { @@ -232,7 +277,7 @@ static unsigned long damon_pa_pageout(struct damon_region *r) } static inline unsigned long damon_pa_mark_accessed_or_deactivate( - struct damon_region *r, bool mark_accessed) + struct damon_region *r, struct damos *s, bool mark_accessed) { unsigned long addr, applied = 0; @@ -241,6 +286,12 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate( if (!page) continue; + + if (damos_pa_filter_out(s, page)) { + put_page(page); + continue; + } + if (mark_accessed) mark_page_accessed(page); else @@ -251,14 +302,16 @@ static inline unsigned long damon_pa_mark_accessed_or_deactivate( return applied * PAGE_SIZE; } -static unsigned long damon_pa_mark_accessed(struct damon_region *r) +static unsigned long damon_pa_mark_accessed(struct damon_region *r, + struct damos *s) { - return damon_pa_mark_accessed_or_deactivate(r, true); + return damon_pa_mark_accessed_or_deactivate(r, s, true); } -static unsigned long damon_pa_deactivate_pages(struct damon_region *r) +static unsigned long damon_pa_deactivate_pages(struct damon_region *r, + struct damos *s) { - return damon_pa_mark_accessed_or_deactivate(r, false); + return damon_pa_mark_accessed_or_deactivate(r, s, false); } static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx, @@ -267,11 +320,11 @@ static unsigned long damon_pa_apply_scheme(struct damon_ctx *ctx, { switch (scheme->action) { case DAMOS_PAGEOUT: - return damon_pa_pageout(r); + return damon_pa_pageout(r, scheme); case DAMOS_LRU_PRIO: - return damon_pa_mark_accessed(r); + return damon_pa_mark_accessed(r, scheme); case DAMOS_LRU_DEPRIO: - return damon_pa_deactivate_pages(r); + return damon_pa_deactivate_pages(r, scheme); case DAMOS_STAT: break; default: