Received: by 2002:a05:6a10:16a7:0:0:0:0 with SMTP id gp39csp1598006pxb; Fri, 6 Nov 2020 14:04:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJzW7GozhzXJIVjEcoFOjqGaVXPzXhrXsipEFThH5RbWpOugyW+jGgEIwaNL83RpZZOKEKFT X-Received: by 2002:a17:906:2b06:: with SMTP id a6mr4317295ejg.283.1604700278390; Fri, 06 Nov 2020 14:04:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604700278; cv=none; d=google.com; s=arc-20160816; b=FTBccWFcOjC9st58mtDTA49l/GBjnwaV00Kcql55t9q7bxzUizFVjoG80Kz5nglb55 seiqZe465dcoWyK7s9XfibFXm4j57sAskxMkTJMsz8PaUzF3bMzqfHRaAOg81M4HjjLB UXy25XnZ6sBYIMNatyYG1SzRgOgGx+hyJNlcBg1A31DMM1g2b0OZM+CKhG1JBDRz8PZt VCquYgYR3r34LuTu9F7UDrMvyk5CX0z39eAyR0zopXzIQnJ3xyuogysrPaeIGkErXO/z rOesMXw1TmlNACihB2et19LSCHkDrxRwCEO5hRkhlXgsrce7mF3R8W/c8UmKfWp1257K jwLQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=9tJLva6MxGP0RlF4GQXWhwyd6Ld/npyROEV+eHgx1qU=; b=n+dfc4WkRWlysST0CE5fwFMk6TgFCTND1JRj3YBSSRjJgpcQ3wY9yM5BBpZ0h/8j/O oVXpvU5A6uXWcR3fRcM19dFtQZEAFKEk9j2shMkYrQQlJ+Z9CQMPTo69LxhMQM5zo4mR k7owJKcQ72NGmDJ6am0XXJW9fGUPZJj5EyPbQjhM6z6c6THRdBhDB+mm7K4gVwbxKKkX GVmYCiXjN7xFYgSQIgP6NIlNw7zjuuo6/gGSXIp7z1NO51bw/wdmiAx/1+RK/TUcj7EB V9oyeJJEGiSCsuOytUaoyix0zFDfGpkpuMwEfhi6FwKUCgIQmLku22gcdw08FPHv5TQz 1/Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=NL260D+H; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id o6si1430877edz.428.2020.11.06.14.04.15; Fri, 06 Nov 2020 14:04:38 -0800 (PST) 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=@gmail.com header.s=20161025 header.b=NL260D+H; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728781AbgKFWCO (ORCPT + 99 others); Fri, 6 Nov 2020 17:02:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728777AbgKFWCO (ORCPT ); Fri, 6 Nov 2020 17:02:14 -0500 Received: from mail-ed1-x542.google.com (mail-ed1-x542.google.com [IPv6:2a00:1450:4864:20::542]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1410BC0613CF for ; Fri, 6 Nov 2020 14:02:14 -0800 (PST) Received: by mail-ed1-x542.google.com with SMTP id t11so2748044edj.13 for ; Fri, 06 Nov 2020 14:02:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=9tJLva6MxGP0RlF4GQXWhwyd6Ld/npyROEV+eHgx1qU=; b=NL260D+Hdtyhvv37KWi1AuDd8qUNq/YasMfWp6VTY5JdVJq4FSlN8W6hy5jt9gPkQl dyfo9NQ9aFO8I4ysr/fZTyBcTFr62NjApqRkingoWZNWX6OOKds2YuicgLMPFy/AJJis QmLKO/uXOzsxFfQU3jO/kLgEBBqPwnfT8NjUSxQ2nT9cHWjP0cvshnVaejd9v5S6GGmq Cseyj41TSNviHkQ2Qt/DOetiP6jEBIWbt2u06rEkcvKNOq2s+c3UlEX8u/Ei/0RZuGgF J3CZQbD9fhbVBTLpDG6QywOaJ0jgCqkiDkknntf+SFewp5utn10WjkbkUvEAe8L7xY5L FsWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=9tJLva6MxGP0RlF4GQXWhwyd6Ld/npyROEV+eHgx1qU=; b=SeG20yiRte9Fk5DoL1ZZsZC7wRsf8SuQQEFsjCHAbDBbeoXlD8ROjS4MlavHIxXIWt eL//+MQ0GJgKrinbKMZpM91hJGwMewduQYT03AlXgasBAr6EBfNwATzmaC+ynbitrf6p Jl1O5WjfvTrqNNRf9/nCw5j8iPwIJ92Jfx5NMOs8PmDTXR13SaTOGu4H0lU556OeRJYd AOF87eTzQOKdcHKXHKuE+3BRimxusu4al5T4h3rwOGjtvdKZ7r0iab7g1SyUAbTnLUk7 fceBVVZjkJ0tpFPuEETMcwKeDc7dO/PEThb0YgYrBc1VVOhtbQS9uy13r0PkeAeIdGoA ZU3g== X-Gm-Message-State: AOAM531WjH/+pz76KRjZhyOt2IP2C/L2DcMJjlL+Wh3cV1BJT3v6v1f2 2YaLU6qF6MdeyCRU5VadUCRaD9OzUPJTH+emo60= X-Received: by 2002:aa7:d2d2:: with SMTP id k18mr4140229edr.290.1604700132754; Fri, 06 Nov 2020 14:02:12 -0800 (PST) MIME-Version: 1.0 References: <20201103130334.13468-1-shy828301@gmail.com> <20201103130334.13468-6-shy828301@gmail.com> In-Reply-To: From: Yang Shi Date: Fri, 6 Nov 2020 14:02:00 -0800 Message-ID: Subject: Re: [PATCH 5/5] mm: migrate: return -ENOSYS if THP migration is unsupported To: Zi Yan Cc: Michal Hocko , Song Liu , Mel Gorman , Jan Kara , Andrew Morton , Linux MM , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 6, 2020 at 12:17 PM Zi Yan wrote: > > On 3 Nov 2020, at 8:03, Yang Shi wrote: > > > In the current implementation unmap_and_move() would return -ENOMEM if > > THP migration is unsupported, then the THP will be split. If split is > > failed just exit without trying to migrate other pages. It doesn't mak= e > > too much sense since there may be enough free memory to migrate other > > pages and there may be a lot base pages on the list. > > > > Return -ENOSYS to make consistent with hugetlb. And if THP split is > > failed just skip and try other pages on the list. > > > > Just skip the whole list and exit when free memory is really low. > > > > Signed-off-by: Yang Shi > > --- > > mm/migrate.c | 62 ++++++++++++++++++++++++++++++++++++++-------------- > > 1 file changed, 46 insertions(+), 16 deletions(-) > > > > diff --git a/mm/migrate.c b/mm/migrate.c > > index 8f6a61c9274b..b3466d8c7f03 100644 > > --- a/mm/migrate.c > > +++ b/mm/migrate.c > > @@ -1172,7 +1172,7 @@ static int unmap_and_move(new_page_t get_new_page= , > > struct page *newpage =3D NULL; > > > > if (!thp_migration_supported() && PageTransHuge(page)) > > - return -ENOMEM; > > + return -ENOSYS; > > > > if (page_count(page) =3D=3D 1) { > > /* page was freed from under us. So we are done. */ > > @@ -1376,6 +1376,20 @@ static int unmap_and_move_huge_page(new_page_t g= et_new_page, > > return rc; > > } > > > > +static inline int try_split_thp(struct page *page, struct page *page2, > > + struct list_head *from) > > +{ > > + int rc =3D 0; > > + > > + lock_page(page); > > + rc =3D split_huge_page_to_list(page, from); > > + unlock_page(page); > > + if (!rc) > > + list_safe_reset_next(page, page2, lru); > > This does not work as expected, right? After macro expansion, we have > page2 =3D list_next_entry(page, lru). Since page2 is passed as a pointer,= the change > does not return back the caller. You need to use the pointer to page2 her= e. > > > + > > + return rc; > > +} > > + > > /* > > * migrate_pages - migrate the pages specified in a list, to the free = pages > > * supplied as the target for the page migration > > @@ -1445,24 +1459,40 @@ int migrate_pages(struct list_head *from, new_p= age_t get_new_page, > > reason, &ret_pages); > > > > switch(rc) { > > + /* > > + * THP migration might be unsupported or the > > + * allocation could've failed so we should > > + * retry on the same page with the THP split > > + * to base pages. > > + * > > + * Head page is retried immediately and tail > > + * pages are added to the tail of the list so > > + * we encounter them after the rest of the list > > + * is processed. > > + */ > > + case -ENOSYS: > > + /* THP migration is unsupported */ > > + if (is_thp) { > > + if (!try_split_thp(page, page2, f= rom)) { > > + nr_thp_split++; > > + goto retry; > > + } > > + > > + nr_thp_failed++; > > + nr_failed +=3D nr_subpages; > > + break; > > + } > > + > > + /* Hugetlb migration is unsupported */ > > + nr_failed++; > > + break; > > case -ENOMEM: > > /* > > - * THP migration might be unsupported or = the > > - * allocation could've failed so we shoul= d > > - * retry on the same page with the THP sp= lit > > - * to base pages. > > - * > > - * Head page is retried immediately and t= ail > > - * pages are added to the tail of the lis= t so > > - * we encounter them after the rest of th= e list > > - * is processed. > > + * When memory is low, don't bother to tr= y to migrate > > + * other pages, just exit. > > The comment does not match the code below. For THPs, the code tries to sp= lit the THP > and migrate the base pages if the split is successful. BTW, actually I don't think -ENOSYS is a proper return value for this case since it typically means "the syscall doesn't exist". IMHO, it should return -EINVAL. And actually the return value doesn't matter since all callers of migrate_pages() just check if the return value !=3D 0. And, neither -ENOSYS nor -EINVAL won't be visible by userspace since migrate_pages() just returns the number of failed pages for this case. Anyway the return value is a little bit messy, it may return -ENOMEM, 0 or nr_failed. But it looks the callers just care about if ret !=3D 0, so it may be better to let it return nr_failed for -ENOMEM case too. > > > */ > > if (is_thp) { > > - lock_page(page); > > - rc =3D split_huge_page_to_list(pa= ge, from); > > - unlock_page(page); > > - if (!rc) { > > - list_safe_reset_next(page= , page2, lru); > > + if (!try_split_thp(page, page2, f= rom)) { > > nr_thp_split++; > > goto retry; > > } > > @@ -1490,7 +1520,7 @@ int migrate_pages(struct list_head *from, new_pag= e_t get_new_page, > > break; > > default: > > /* > > - * Permanent failure (-EBUSY, -ENOSYS, et= c.): > > + * Permanent failure (-EBUSY, etc.): > > * unlike -EAGAIN case, the failed page i= s > > * removed from migration page list and n= ot > > * retried in the next outer loop. > > -- > > 2.26.2 > > > =E2=80=94 > Best Regards, > Yan Zi