From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 88667C433ED for ; Wed, 12 May 2021 08:55:30 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id C109F613CD for ; Wed, 12 May 2021 08:55:29 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C109F613CD Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id F29A46B0036; Wed, 12 May 2021 04:55:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id ED9A26B006E; Wed, 12 May 2021 04:55:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA1536B0070; Wed, 12 May 2021 04:55:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0114.hostedemail.com [216.40.44.114]) by kanga.kvack.org (Postfix) with ESMTP id C1AAA6B0036 for ; Wed, 12 May 2021 04:55:28 -0400 (EDT) Received: from smtpin07.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 72CC58249980 for ; Wed, 12 May 2021 08:55:28 +0000 (UTC) X-FDA: 78131970336.07.96D079D Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf20.hostedemail.com (Postfix) with ESMTP id B57BE3C5 for ; Wed, 12 May 2021 08:55:27 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 7B65EAF65; Wed, 12 May 2021 08:55:26 +0000 (UTC) Date: Wed, 12 May 2021 10:55:22 +0200 From: Oscar Salvador To: Naoya Horiguchi Cc: Muchun Song , linux-mm@kvack.org, Andrew Morton , Mike Kravetz , Michal Hocko , Tony Luck , Naoya Horiguchi , linux-kernel@vger.kernel.org Subject: Re: [PATCH v3 2/2] mm,hwpoison: make get_hwpoison_page call get_any_page() Message-ID: <20210512085522.GB14726@linux> References: <20210511151016.2310627-1-nao.horiguchi@gmail.com> <20210511151016.2310627-3-nao.horiguchi@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210511151016.2310627-3-nao.horiguchi@gmail.com> User-Agent: Mutt/1.10.1 (2018-07-13) Authentication-Results: imf20.hostedemail.com; dkim=none; dmarc=none; spf=pass (imf20.hostedemail.com: domain of osalvador@suse.de designates 195.135.220.15 as permitted sender) smtp.mailfrom=osalvador@suse.de X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: B57BE3C5 X-Stat-Signature: x5ntginra67htw34iuzw9z8dwajug5o5 Received-SPF: none (suse.de>: No applicable sender policy available) receiver=imf20; identity=mailfrom; envelope-from=""; helo=mx2.suse.de; client-ip=195.135.220.15 X-HE-DKIM-Result: none/none X-HE-Tag: 1620809727-631904 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Wed, May 12, 2021 at 12:10:16AM +0900, Naoya Horiguchi wrote: > From: Naoya Horiguchi > > Now __get_hwpoison_page() could return -EBUSY in a race condition, > so it's helpful to handle it by retrying. We already have retry > logic, so make get_hwpoison_page() call get_any_page() when called > from memory_failure(). As I stated in your previous patch, I think you should start returning -EBUSY from this patch onwards. > static int get_any_page(struct page *p, unsigned long flags) > { > int ret = 0, pass = 0; > @@ -1152,50 +1136,76 @@ static int get_any_page(struct page *p, unsigned long flags) > count_increased = true; > > try_again: > - if (!count_increased && !__get_hwpoison_page(p)) { > - if (page_count(p)) { > - /* We raced with an allocation, retry. */ > - if (pass++ < 3) > - goto try_again; > - ret = -EBUSY; > - } else if (!PageHuge(p) && !is_free_buddy_page(p)) { > - /* We raced with put_page, retry. */ > - if (pass++ < 3) > - goto try_again; > - ret = -EIO; > + if (!count_increased) { > + ret = __get_hwpoison_page(p); > + if (!ret) { > + if (page_count(p)) { > + /* We raced with an allocation, retry. */ > + if (pass++ < 3) > + goto try_again; > + ret = -EBUSY; > + } else if (!PageHuge(p) && !is_free_buddy_page(p)) { > + /* We raced with put_page, retry. */ > + if (pass++ < 3) > + goto try_again; > + ret = -EIO; > + } > + goto out; > } > + } I think this can be improved. We cannot have -EBUSY unless we come from __get_hwpoison_page() (!count_increased), so I think a much more natural approach would be to stuff the hunk below in there, and then place the other stuff in an else, so something like: if (!count_increased) { ret = __get_hwpoison_page(p); if (!ret) { if (page_count(p)) { /* We raced with an allocation, retry. */ if (pass++ < 3) goto try_again; ret = -EBUSY; } else if (!PageHuge(p) && !is_free_buddy_page(p)) { /* We raced with put_page, retry. */ if (pass++ < 3) goto try_again; ret = -EIO; } goto out; } else if (ret == -EBUSY) { /* We raced with freeing huge page to buddy, retry. */ if (pass++ < 3) goto try_again; } } else { /* We do already have a refcount for this page, see if we can * handle it. */ if (PageHuge(p) || PageLRU(p) || __PageMovable(p)) { ret = 1; } else { /* A page we cannot handle. Check... } } Other than that, looks good to me. > + > + if (ret == -EBUSY) { > + /* We raced with freeing huge page to buddy, retry. */ > + if (pass++ < 3) > + goto try_again; -- Oscar Salvador SUSE L3