Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp4281285pxj; Wed, 12 May 2021 01:58:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzDGA5WRcbZ1JggL9BMNvse1GLpgxLGsEbhcPOlBK/xhBvHM+pY4ZakXGUSzC3XZzf3WIw/ X-Received: by 2002:a05:6402:c9b:: with SMTP id cm27mr35720573edb.258.1620809927927; Wed, 12 May 2021 01:58:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1620809927; cv=none; d=google.com; s=arc-20160816; b=MiUAggCWLXhZfkBjUj0hB9c2ym0+pY/HfnHxbQYBGTBDWIagTgpcN7WEa6izvcWYUr KJAkBHsUj4QKsq8t2Pka0mut4ESMYIYg/L6R1hTnt5sTXzvXD0JT7/WviurmX+mA0Fkm qOTZVGP+grS0sLxrKvWbrKOnX0wpNaZgjAPNvkTK2/LmF/mZtjBVD4vd5vhAhDXOFiS3 iYbRFEYBIHSG9SMGR+mCwFVpncotWcXpz6xv+mCNc0jDuI125dPSAlXKHYwh4NBV14uW Y0jZMB68DwL6HDadyctKf/BSNbYfiOt6ygl1YSGIIww4wsbVh6TQ3eneJhN8gagUyjfu 90jA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:user-agent:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=8Ar4TcnXKL9gCd9Ti3Vg5HIWMODBnCPV5dQ3mbrcvW0=; b=tckrBsJWqVTSxYF6pcnXYrVrn6DuC/pelNxwg3B79CiifinM4G7MyCLdWPRrnusB8s ScHkIWEEfMOgu9wDoBHZzTSDnLTi7ZN1X/gpal1D+Id5Kb/cfiZiaVPRN5+/rtY28LO8 ZJH9+20n9GY27Jnn6fQqdUKBTlEEnxWNgQ+mqnxzh0kChveO1Fkm3LOPbtkVO4HRKPwW NpQRxwKn13MoKZV80E0eQ9cP+nivO4ZgrrA/JeOhbH61Ka3IuyOpLCOmGCQ97uzhW6vg iv7AnjL3bELZPcCuIJjZ5HtYH0WPoftOQ+TW+B5yvfMPZaW/XznxvJVmuK6fSanDJF5+ JdFg== ARC-Authentication-Results: i=1; mx.google.com; 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 z14si19893231eja.696.2021.05.12.01.58.24; Wed, 12 May 2021 01:58: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; 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 S230253AbhELI4i (ORCPT + 99 others); Wed, 12 May 2021 04:56:38 -0400 Received: from mx2.suse.de ([195.135.220.15]:49360 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbhELI4f (ORCPT ); Wed, 12 May 2021 04:56:35 -0400 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) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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