Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp1397368ybt; Thu, 18 Jun 2020 07:48:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7z236WDvBEt65IBApr7TljqhetocmDqVG8XO45mtiEtauFJCCxeJZTSkoXi7ZTV/L0yc1 X-Received: by 2002:a17:906:11d9:: with SMTP id o25mr4093855eja.377.1592491738223; Thu, 18 Jun 2020 07:48:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592491738; cv=none; d=google.com; s=arc-20160816; b=h1+oeP54fpbNg4pV6XgsBNvGTu436Q98Ai+FZiKEAvdD4VuUYihzU0jHOHD1oMEXNR /M4s10gh8i2JcQ2S9SXbBsFiQVWJCLeqhkI1/KZhrR3aRQnS5GZScLzDLszkzC9Ul6U3 r6zfOv95wwiIsSyI40zojF6+9bN0v5Pgegw165LWEYFPxUTF1D4BTfd2AWGA1uB8/L/t I2Eenb26CjQBd9Lf6ssWO8vIcrAWG/Xpss3M5+qwbuxRI14HtmL6gQLU6Ux2LQ2HooQS t/UgDFRqieXgYtxw9lkuU618SPQE8HjSb/9J0PKMiO2QmvAforW7hUDWPpzBX13tmyPj 2VrA== 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 :reply-to:references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=L8y2vzO4eFciFziI46a/ttSbeGYaIdwkqPPuYZk9V/Y=; b=PetF69GERjQ6l7Fyl6P+2hVe9TzDVewJbEoknRIeDdwKPLilI8hOXHavfFa6EjKoQa s5CtusaT2m2JNqE1MVkWq1FUt8PoTs/+ygksrS6nESyxg1qgKLCtkM4VyaaoVeabjB9g Guct1s+ARHsIBMn/X33rQ7+Jv8WSjk+ZOgQMzDw9Phwaz4bdb12JxmAN+SgNePIv6byO EKBhj1+3IhztxKSNU4SnFB7GXf5YlmkV9dx+qAPezM78z5e5Z46WrI1msC3O5g28itZF 5oG0KzDZuLKgyUPNHQlSZ8lzvzzHqvDod1bOozXEZYLUmVwH8d0YlROtL5qhhVaJhRLc RtRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=YeULpx9I; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id qx4si2013139ejb.176.2020.06.18.07.48.35; Thu, 18 Jun 2020 07:48:58 -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=fail header.i=@kernel-dk.20150623.gappssmtp.com header.s=20150623 header.b=YeULpx9I; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730934AbgFROqP (ORCPT + 99 others); Thu, 18 Jun 2020 10:46:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57354 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730957AbgFROoJ (ORCPT ); Thu, 18 Jun 2020 10:44:09 -0400 Received: from mail-pj1-x1042.google.com (mail-pj1-x1042.google.com [IPv6:2607:f8b0:4864:20::1042]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2D8FAC0613EF for ; Thu, 18 Jun 2020 07:44:08 -0700 (PDT) Received: by mail-pj1-x1042.google.com with SMTP id h95so2771898pje.4 for ; Thu, 18 Jun 2020 07:44:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel-dk.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=L8y2vzO4eFciFziI46a/ttSbeGYaIdwkqPPuYZk9V/Y=; b=YeULpx9IMVYlet06hXXtF3Dyovfb6OWV7znBhPslocYv61JEKGOzA86Uf7KlkwQUxA 5veTkQm0U3FiHje/G2qBCvINtR+5H6+EjnG+6Sf5DBiwhwEgiK3ZySkgoWKeRlArsl6Z KII1sM40sgw0BBBEt/0RNUdVdIscLTYaAk11C3WKb8/EKEdqvKbfubfLIO/VBQ2Xx9WL CEYBtGHqlJYku+rfQdHayepPiSv6ME4oZxtjXE8I56CTLxFCqrzXuobRRnwbzTHobf+i uKAVIMjqM417ECasSBzSLduZSGdbDtTFAHLkWJ12coSXUTQ7pSi5y5D2Y4Jzync6tV9q xrBQ== 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:reply-to:mime-version:content-transfer-encoding; bh=L8y2vzO4eFciFziI46a/ttSbeGYaIdwkqPPuYZk9V/Y=; b=iM8Lt4aElcXcor32u9N4CusarJ+vkGksP5QRtwZuiENIGH96FGZzn9bTuQ1hecakuR gSGewF+6zmMaLebJcn6NHXuLR0QbU1JV6tWYCHMRvVYYGM0nvaA1U8Llu/v0PdVOjlB7 Ac8NVw256JN+pzp4/umYKK1mvauoxf3anWzQJpEw/SYw26XAYk8TtNirU7Qw9O/0NyIe NDa+RGP3/zDVnsRJQymbdpIxlQWFPyJnApK82UFJEzZ0XG6UeWmSKjveuEhwuGpNFFyx WSg4GnDGBq9A4+HcIqawEhe1UTBfC2EDhQFZKsd4HHQLl2oX/ogAJeq35df0FA+UFJkw vdkg== X-Gm-Message-State: AOAM53030EW+2EtdsvpsP6UmXEkJe4VyF2FX9YCYKJyYP0ejoGOA860L WNg9emQtZtvFxptwhKxByKV8/A== X-Received: by 2002:a17:902:8690:: with SMTP id g16mr4021455plo.257.1592491447688; Thu, 18 Jun 2020 07:44:07 -0700 (PDT) Received: from x1.localdomain ([65.144.74.34]) by smtp.gmail.com with ESMTPSA id g9sm3127197pfm.151.2020.06.18.07.44.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 18 Jun 2020 07:44:06 -0700 (PDT) From: Jens Axboe To: io-uring@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, akpm@linux-foundation.org, Jens Axboe , Johannes Weiner Subject: [PATCH 06/15] mm: abstract out wake_page_match() from wake_page_function() Date: Thu, 18 Jun 2020 08:43:46 -0600 Message-Id: <20200618144355.17324-7-axboe@kernel.dk> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200618144355.17324-1-axboe@kernel.dk> References: <20200618144355.17324-1-axboe@kernel.dk> Reply-To: "[PATCHSET v7 0/15]"@vger.kernel.org, Add@vger.kernel.org, support@vger.kernel.org, for@vger.kernel.org, async@vger.kernel.org, buffered@vger.kernel.org, reads@vger.kernel.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 No functional changes in this patch, just in preparation for allowing more callers. Acked-by: Johannes Weiner Signed-off-by: Jens Axboe --- include/linux/pagemap.h | 37 +++++++++++++++++++++++++++++++++++++ mm/filemap.c | 35 ++++------------------------------- 2 files changed, 41 insertions(+), 31 deletions(-) diff --git a/include/linux/pagemap.h b/include/linux/pagemap.h index cf2468da68e9..2f18221bb5c8 100644 --- a/include/linux/pagemap.h +++ b/include/linux/pagemap.h @@ -496,6 +496,43 @@ static inline pgoff_t linear_page_index(struct vm_area_struct *vma, return pgoff; } +/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c */ +struct wait_page_key { + struct page *page; + int bit_nr; + int page_match; +}; + +struct wait_page_queue { + struct page *page; + int bit_nr; + wait_queue_entry_t wait; +}; + +static inline int wake_page_match(struct wait_page_queue *wait_page, + struct wait_page_key *key) +{ + if (wait_page->page != key->page) + return 0; + key->page_match = 1; + + if (wait_page->bit_nr != key->bit_nr) + return 0; + + /* + * Stop walking if it's locked. + * Is this safe if put_and_wait_on_page_locked() is in use? + * Yes: the waker must hold a reference to this page, and if PG_locked + * has now already been set by another task, that task must also hold + * a reference to the *same usage* of this page; so there is no need + * to walk on to wake even the put_and_wait_on_page_locked() callers. + */ + if (test_bit(key->bit_nr, &key->page->flags)) + return -1; + + return 1; +} + extern void __lock_page(struct page *page); extern int __lock_page_killable(struct page *page); extern int __lock_page_or_retry(struct page *page, struct mm_struct *mm, diff --git a/mm/filemap.c b/mm/filemap.c index 3378d4fca883..c3175dbd8fba 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -987,43 +987,16 @@ void __init pagecache_init(void) page_writeback_init(); } -/* This has the same layout as wait_bit_key - see fs/cachefiles/rdwr.c */ -struct wait_page_key { - struct page *page; - int bit_nr; - int page_match; -}; - -struct wait_page_queue { - struct page *page; - int bit_nr; - wait_queue_entry_t wait; -}; - static int wake_page_function(wait_queue_entry_t *wait, unsigned mode, int sync, void *arg) { struct wait_page_key *key = arg; struct wait_page_queue *wait_page = container_of(wait, struct wait_page_queue, wait); + int ret; - if (wait_page->page != key->page) - return 0; - key->page_match = 1; - - if (wait_page->bit_nr != key->bit_nr) - return 0; - - /* - * Stop walking if it's locked. - * Is this safe if put_and_wait_on_page_locked() is in use? - * Yes: the waker must hold a reference to this page, and if PG_locked - * has now already been set by another task, that task must also hold - * a reference to the *same usage* of this page; so there is no need - * to walk on to wake even the put_and_wait_on_page_locked() callers. - */ - if (test_bit(key->bit_nr, &key->page->flags)) - return -1; - + ret = wake_page_match(wait_page, key); + if (ret != 1) + return ret; return autoremove_wake_function(wait, mode, sync, key); } -- 2.27.0