Received: by 2002:a05:6a10:6744:0:0:0:0 with SMTP id w4csp46009pxu; Tue, 6 Oct 2020 18:16:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkR4xyiiIUUvV9R7LURV6+mkg31zo00c9+RFcL/oVjYCxUsL4PSSLGycx2J1UI96Iydin8 X-Received: by 2002:a17:906:b45:: with SMTP id v5mr847944ejg.353.1602033407427; Tue, 06 Oct 2020 18:16:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1602033407; cv=none; d=google.com; s=arc-20160816; b=YKV53zY95RumQwyJnZIvqWB3GKtbpuG8RG21XdqBMDs1ap5u9xBbjzsKar7gZTH3hI 8hQLCbyeRhJmY2NWlskGmFqQR+sIHLtt5nHiv/EZIMv2yKVkUfhs/hY7f/mvV/3GoUah FN/yET7y6NdEkll7LAJvgaXTJA8nFx3MVHf1/ONlIIPfudRq1K/nNvi44dx3V0cVtzph wBz7ZmJXchcEniJ240Otbj/3dKpvADdQEzNgGncnaNsw43GTW7Vp1ni9lbqN2jxfNRMm kUa/7GeRmsVgMgCyflziSXzzVBpEzlJtF8O/uT1joqk3OJkzsTgJ6y33iD9tdrFfj4wr vdgQ== 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=dIjWvKp1A0e0W4GIot1k+x52KQno6rPc1gzlEYRF8k0=; b=sCXe5KNgLuZiuHEVltP13c9WxXFccB81PIWWTt7FyjDu36iSiwFbuWjM+PnnO/60h4 PCQB382KckBgHvjDWKvg75Fz26P1OVgvF+UMLzC3uSS5MxgVMWbSljXU+I+SM6mZ5ckX Zg2DTNvOey2mwf05st8YFsqfnaOE3UWs3lXwfX/VSsuwnDT0epWamGKgMTjdDoH4svCA yUbk3NPojAtmcSqgy/3ici7DEBQ1wySOmYitfVRXeR2WXwDxN5nN2n8LBAb48De2qrfW gI3YOdJSgMZSRdQeiXBTGbbv2WyDR8PlswfXo/gKVsGxjGN9Rk+8ZHC4Iqf7t8vSOzmJ C9Ow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=WaUzWBnC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v20si306327ejg.640.2020.10.06.18.16.24; Tue, 06 Oct 2020 18:16:47 -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=@redhat.com header.s=mimecast20190719 header.b=WaUzWBnC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727458AbgJGBIL (ORCPT + 99 others); Tue, 6 Oct 2020 21:08:11 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:20811 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727391AbgJGBHv (ORCPT ); Tue, 6 Oct 2020 21:07:51 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602032868; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dIjWvKp1A0e0W4GIot1k+x52KQno6rPc1gzlEYRF8k0=; b=WaUzWBnC6XXous2jtkS4XcNFh6ymJcdYp3EGEYoLutud6gjKMlkMEYWehYkp2Djlyf4O6q oaHx/OC+z5IeV6VdycYUdk87hIGHXISYmjs0LoXPDbJwK+I3Tf+3L0+W/+GFhZYZB3A0Zc h8bHfEMmVOXd76OY+AQruRlP7ZQtN/s= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-411-Wl-T1OHfPe-QKuHoKN7tOw-1; Tue, 06 Oct 2020 21:07:46 -0400 X-MC-Unique: Wl-T1OHfPe-QKuHoKN7tOw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id AAC4A425D1; Wed, 7 Oct 2020 01:07:44 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-119-161.rdu2.redhat.com [10.10.119.161]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9FFFB5D9D2; Wed, 7 Oct 2020 01:07:43 +0000 (UTC) From: jglisse@redhat.com To: linux-kernel@vger.kernel.org Cc: =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , linux-mm@kvack.org, linux-fsdevel@vger.kernel.org, Andrew Morton , Alexander Viro , Tejun Heo , Jan Kara , Josef Bacik Subject: [PATCH 13/14] mm: add struct address_space to isolate_page() callback Date: Tue, 6 Oct 2020 21:06:02 -0400 Message-Id: <20201007010603.3452458-14-jglisse@redhat.com> In-Reply-To: <20201007010603.3452458-1-jglisse@redhat.com> References: <20201007010603.3452458-1-jglisse@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jérôme Glisse This is part of patchset to remove dependency on struct page.mapping field so that we can temporarily update it to point to a special structure tracking temporary page state (note that original mapping pointer is preserved and can still be accessed but at a cost). Add struct address_space to isolate_page() callback arguments. Note that this patch does not make use of the new argument, nor does it use a valid one at call site (by default this patch just use NULL for new argument value). Use following script (from root of linux kernel tree): ./that-script.sh that-semantic-patch.spatch %<-------------------------------------------------------------------- #!/bin/sh spatch_file=$1 echo PART1 =========================================================== # P1 find callback functions name spatch --dir . --no-includes -D part1 --sp-file $spatch_file echo PART2 =========================================================== # P2 change callback function prototype cat /tmp/unicorn-functions | sort | uniq | while read func ; do for file in $( git grep -l $func -- '*.[ch]' ) ; do echo $file spatch --no-includes --in-place -D part2 \ -D fn=$func --sp-file $spatch_file $file done done echo PART 3 ========================================================== # P3 find all function which call the callback spatch --dir . --include-headers -D part3 --sp-file $spatch_file echo PART 4=========================================================== # P4 change all funcitons which call the callback cat /tmp/unicorn-files | sort | uniq | while read file ; do echo $file spatch --no-includes --in-place -D part4 \ --sp-file $spatch_file $file done -------------------------------------------------------------------->% With the following semantic patch: %<-------------------------------------------------------------------- virtual part1, part2, part3, part4 // ---------------------------------------------------------------------------- // Part 1 is grepping all function that are use as callback for isolate_page. // initialize file where we collect all function name (erase it) @initialize:python depends on part1@ @@ file=open('/tmp/unicorn-functions', 'w') file.close() // match function name use as a callback @p1r2 depends on part1@ identifier I1, FN; @@ struct address_space_operations I1 = {..., .isolate_page = FN, ...}; @script:python p1r3 depends on p1r2@ funcname << p1r2.FN; @@ if funcname != "NULL": file=open('/tmp/unicorn-functions', 'a') file.write(funcname + '\n') file.close() // ------------------------------------------------------------------- // Part 2 modify callback // Add address_space argument to the function (isolate_page callback one) @p2r1 depends on part2@ identifier virtual.fn; identifier I1, I2; type R, T1, T2; @@ R fn( +struct address_space *__mapping, T1 I1, T2 I2) { ... } @p2r2 depends on part2@ identifier virtual.fn; identifier I1, I2; type R, T1, T2; @@ R fn( +struct address_space *__mapping, T1 I1, T2 I2); @p2r3 depends on part2@ identifier virtual.fn; expression E1, E2; @@ fn( +MAPPING_NULL, E1, E2) // ---------------------------------------------------------------------------- // Part 3 is grepping all function that are use the callback for isolate_page. // initialize file where we collect all function name (erase it) @initialize:python depends on part3@ @@ file=open('/tmp/unicorn-files', 'w') file.write("./include/linux/pagemap.h\n") file.write("./include/linux/mm.h\n") file.write("./include/linux/fs.h\n") file.write("./mm/readahead.c\n") file.write("./mm/filemap.c\n") file.close() @p3r1 depends on part3 exists@ expression E1, E2, E3; identifier FN; position P; @@ FN@P(...) {... ( E1.a_ops->isolate_page(E2, E3) | E1->a_ops->isolate_page(E2, E3) ) ...} @script:python p3r2 depends on p3r1@ P << p3r1.P; @@ file=open('/tmp/unicorn-files', 'a') file.write(P[0].file + '\n') file.close() // ------------------------------------------------------------------- // Part 4 generic modification @p4r1 depends on part4@ type R; @@ struct address_space_operations { ... R (*isolate_page)( +struct address_space *, struct page *, ...); ... }; @p4r2 depends on part4@ expression E1, E2, E3; @@ E1.a_ops->isolate_page( +MAPPING_NULL, E2, E3) @p4r3 depends on part4@ expression E1, E2, E3; @@ E1->a_ops->isolate_page( +MAPPING_NULL, E2, E3) -------------------------------------------------------------------->% Signed-off-by: Jérôme Glisse Cc: linux-mm@kvack.org Cc: linux-fsdevel@vger.kernel.org Cc: Andrew Morton Cc: Alexander Viro Cc: linux-fsdevel@vger.kernel.org Cc: Tejun Heo Cc: Jan Kara Cc: Josef Bacik --- include/linux/balloon_compaction.h | 5 +++-- include/linux/fs.h | 3 ++- mm/balloon_compaction.c | 3 ++- mm/migrate.c | 2 +- mm/z3fold.c | 3 ++- mm/zsmalloc.c | 3 ++- 6 files changed, 12 insertions(+), 7 deletions(-) diff --git a/include/linux/balloon_compaction.h b/include/linux/balloon_compaction.h index 07b235161d040..c1e45339a53c1 100644 --- a/include/linux/balloon_compaction.h +++ b/include/linux/balloon_compaction.h @@ -80,8 +80,9 @@ static inline void balloon_devinfo_init(struct balloon_dev_info *balloon) #ifdef CONFIG_BALLOON_COMPACTION extern const struct address_space_operations balloon_aops; -extern bool balloon_page_isolate(struct page *page, - isolate_mode_t mode); +extern bool balloon_page_isolate(struct address_space *__mapping, + struct page *page, + isolate_mode_t mode); extern void balloon_page_putback(struct address_space *__mapping, struct page *page); extern int balloon_page_migrate(struct address_space *mapping, diff --git a/include/linux/fs.h b/include/linux/fs.h index 21f179e7c5daa..6798a13e3c980 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -408,7 +408,8 @@ struct address_space_operations { */ int (*migratepage) (struct address_space *, struct page *, struct page *, enum migrate_mode); - bool (*isolate_page)(struct page *, isolate_mode_t); + bool (*isolate_page)(struct address_space *, struct page *, + isolate_mode_t); void (*putback_page)(struct address_space *, struct page *); int (*launder_page) (struct address_space *, struct page *); int (*is_partially_uptodate) (struct address_space *, struct page *, diff --git a/mm/balloon_compaction.c b/mm/balloon_compaction.c index abc4a63df9903..ed9120e6c9bfe 100644 --- a/mm/balloon_compaction.c +++ b/mm/balloon_compaction.c @@ -203,7 +203,8 @@ EXPORT_SYMBOL_GPL(balloon_page_dequeue); #ifdef CONFIG_BALLOON_COMPACTION -bool balloon_page_isolate(struct page *page, isolate_mode_t mode) +bool balloon_page_isolate(struct address_space *__mapping, struct page *page, + isolate_mode_t mode) { struct balloon_dev_info *b_dev_info = balloon_page_device(page); diff --git a/mm/migrate.c b/mm/migrate.c index 3fba7429151bf..a3220050fbe05 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -126,7 +126,7 @@ int isolate_movable_page(struct page *page, isolate_mode_t mode) mapping = page_mapping(page); VM_BUG_ON_PAGE(!mapping, page); - if (!mapping->a_ops->isolate_page(page, mode)) + if (!mapping->a_ops->isolate_page(MAPPING_NULL, page, mode)) goto out_no_isolated; /* Driver shouldn't use PG_isolated bit of page->flags */ diff --git a/mm/z3fold.c b/mm/z3fold.c index 37453a14257a4..4ca02bb55a56b 100644 --- a/mm/z3fold.c +++ b/mm/z3fold.c @@ -1566,7 +1566,8 @@ static u64 z3fold_get_pool_size(struct z3fold_pool *pool) return atomic64_read(&pool->pages_nr); } -static bool z3fold_page_isolate(struct page *page, isolate_mode_t mode) +static bool z3fold_page_isolate(struct address_space *__mapping, + struct page *page, isolate_mode_t mode) { struct z3fold_header *zhdr; struct z3fold_pool *pool; diff --git a/mm/zsmalloc.c b/mm/zsmalloc.c index 99d74c6e98216..c896f069e5b0a 100644 --- a/mm/zsmalloc.c +++ b/mm/zsmalloc.c @@ -1914,7 +1914,8 @@ static void replace_sub_page(struct size_class *class, struct zspage *zspage, __SetPageMovable(newpage, page_mapping(oldpage)); } -static bool zs_page_isolate(struct page *page, isolate_mode_t mode) +static bool zs_page_isolate(struct address_space *__mapping, + struct page *page, isolate_mode_t mode) { struct zs_pool *pool; struct size_class *class; -- 2.26.2