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=-9.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable 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 6D4C3C55178 for ; Fri, 6 Nov 2020 21:53:42 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B2153208C7 for ; Fri, 6 Nov 2020 21:53:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DiqBNJDr" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B2153208C7 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B6A6D6B0036; Fri, 6 Nov 2020 16:53:40 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B1AF96B005C; Fri, 6 Nov 2020 16:53:40 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A094F6B005D; Fri, 6 Nov 2020 16:53:40 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0237.hostedemail.com [216.40.44.237]) by kanga.kvack.org (Postfix) with ESMTP id 721E66B0036 for ; Fri, 6 Nov 2020 16:53:40 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay01.hostedemail.com (Postfix) with ESMTP id 0E4F7180AD820 for ; Fri, 6 Nov 2020 21:53:40 +0000 (UTC) X-FDA: 77455345800.15.box93_39127e1272d5 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin15.hostedemail.com (Postfix) with ESMTP id CBE4E1814B0C7 for ; Fri, 6 Nov 2020 21:53:39 +0000 (UTC) X-HE-Tag: box93_39127e1272d5 X-Filterd-Recvd-Size: 9662 Received: from mail-ej1-f66.google.com (mail-ej1-f66.google.com [209.85.218.66]) by imf43.hostedemail.com (Postfix) with ESMTP for ; Fri, 6 Nov 2020 21:53:38 +0000 (UTC) Received: by mail-ej1-f66.google.com with SMTP id cw8so3935862ejb.8 for ; Fri, 06 Nov 2020 13:53:38 -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=4Lrz5uJAiiLESdTPjmylRgOOL6zFs7nMEo6gXUlcAvc=; b=DiqBNJDrEa7mvU872CK0Pi6oRMRNNNJoLPeoOQrOk9I5zFPe1tNJIhFO2TGfkwbudb G82Vjx8lYZJ/NK2yOfoCk8WfbPo++S1Wh3F/NHqDnVWi42d1fQsOmU3NRU630a9ZRXfX J1/XKXM8wwb/uWSccP+PzxZmgZKwrPLzxiKA+Ouu+jLAMqtWr3cvCEjVHvdwpd04n6Yi PBDp9hHowksWwOO93kCcYc3ccMmac9UVvqKflXmK8vR8rYD0vHNuR58X8kDa2LBXgnKK JXE5HEeF8OYwOfpjpngoS2bYpEy+s2nvjZoMZmMmROPnGutsrfKMK3XhfkAWfRhWRlUT yGjA== 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=4Lrz5uJAiiLESdTPjmylRgOOL6zFs7nMEo6gXUlcAvc=; b=M2+2qegs9untDoB+2UxZJEcG4eZTH2X7dYXsbdKFbUJ40bcdvlrUgNfm46rCxtfhZz iKlu0aYON8hPikeWmCNFN2Q/u3NvMl5aDc0WJuDd7KY/JYtU917SuoujEa3mOxmT8c0W gGYT2ttCtXwALQhgOTFt5+SsCeHtm2LcZ7ZG6Ba+zKRxgBFzvoRg5IcDbZZ0jPI8tR7o nzOJH0m+no5pybJZ8ozfdNX/XwF3k+qjr9LuoFyb9nZ3qutYydeuYBZMkexzj5gXl/bx 9KmKC+TasBC1BL+E8wIMLKY8Ij77KEv7LRX+unsibOI0OvEmZ8VvWCsiuFzoUqQa4IcN /X0w== X-Gm-Message-State: AOAM533oxaiYc1Q1KLW8ayYI5GVTQ0eJm8TmH2Ej1OZ+nrPtAdqFw69z 6CtV1gErRJLvUZsnKlFSpiJUmj6yKyFPsQp+luQ= X-Google-Smtp-Source: ABdhPJwsh3aQno/4dYUGnxDieXScGGhq/yhW6CooR+F1wL41cYWyZXHwCubnIlbLPY+WBzVNxyr0fS0jmGGk25u+uIY= X-Received: by 2002:a17:906:519b:: with SMTP id y27mr3901493ejk.25.1604699617454; Fri, 06 Nov 2020 13:53:37 -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 13:53:25 -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 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 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. Yes, I should pass in **page2. Thanks for catching this. > > > + > > + 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. The comment here just covers the "goto out" rather than the split because I thought it is covered by the comment before "case -ENOSYS", which says "unsupported or the allocation could've failed", so I didn't repeat here. > > > */ > > 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