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=-5.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 80440C6369E for ; Thu, 3 Dec 2020 01:35:12 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id B97BA20B80 for ; Thu, 3 Dec 2020 01:35:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B97BA20B80 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=soleen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id B8D326B005C; Wed, 2 Dec 2020 20:35:10 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B3FB56B005D; Wed, 2 Dec 2020 20:35:10 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 9DF146B0068; Wed, 2 Dec 2020 20:35:10 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0099.hostedemail.com [216.40.44.99]) by kanga.kvack.org (Postfix) with ESMTP id 885416B005C for ; Wed, 2 Dec 2020 20:35:10 -0500 (EST) Received: from smtpin30.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 528B83638 for ; Thu, 3 Dec 2020 01:35:10 +0000 (UTC) X-FDA: 77550252780.30.band36_000b063273b7 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin30.hostedemail.com (Postfix) with ESMTP id 3164B180B3AA7 for ; Thu, 3 Dec 2020 01:35:10 +0000 (UTC) X-HE-Tag: band36_000b063273b7 X-Filterd-Recvd-Size: 7706 Received: from mail-ed1-f65.google.com (mail-ed1-f65.google.com [209.85.208.65]) by imf07.hostedemail.com (Postfix) with ESMTP for ; Thu, 3 Dec 2020 01:35:09 +0000 (UTC) Received: by mail-ed1-f65.google.com with SMTP id q16so284326edv.10 for ; Wed, 02 Dec 2020 17:35:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=soleen.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NwHhRJsP3DZwew8JQ92NqQyNUaCSoTst/Bc5po5pW7I=; b=M2fDHg/GuAjypin1DrEff5pK/6of2VtUHfBoE2rdszAyyX1POwuZbZhvqG8f0n6EkV 0W8Wu4SCS7CjgwTcjDfHxMoNXAwLv2GDZ6m/1mw7MSkMhkE0FDVevbA6KYGH4EAJYPtL K54yaOv+NIJsz7g4x5fapWRMeVIBTK2+4xu4mYfqwTC05o5n7Tgtcwya5K47lOUtKPDT /VJ60S+YLMCAncwA0QIT88wM/XG7R2IiB5c4fec6JLSGNBINQ6M9iVZlguaqN9r2i5/8 ov55uqiFheADaTfERJnyYDLmIl+N81yqTlzAtnCAsiJq8c00DFB93o865uMQpFyYKMOX oFyw== 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; bh=NwHhRJsP3DZwew8JQ92NqQyNUaCSoTst/Bc5po5pW7I=; b=BvdtqqgdfJ1eaq8PF+H4dgSV0v+Szpnl17d4cwYbbbOHDk7RcfeeXGlBbHo0uhf7sJ KETlEAiKKlFpUG8i1oaWRJgHQI5FE7ACq1hUzGcqS67q++Dvl6uUz8GNhAEfGUNXzQGo 9jorOhvtUi/Tc421L5ewfDIzF8nvNnJyZQyzKI+27gFQeiTOzOZWV/AOmF8oiYkiCFo5 aZcxrWUOajgvTR8vMCrW8I9xOu7dlHxhZ4rIUp4AAxE/E8NQD/Vrxpb1z1IofxUOW4LP dUG1ubj/FdJyDf9bz1o4SF2MKgBL7kCzSSU3iW8oaaXy5TSkcofAkGJAi6Rbekrc7VFu 0rZA== X-Gm-Message-State: AOAM532ZndrOyN/VbEXGr19LB/PtyQ34IBqr91N7UNBYsEqSAlAV3s0A K9TjswttkJNWuZJL/VdjVmnMwMHlIxDOkxQre0DwaQ== X-Google-Smtp-Source: ABdhPJwK/jopuKSOlSKkXDBQPpswTyQag77kb7gGmBhCTsbhPtwsRix/53oObBaUNeEoL/jBVDryzigMFOdVB9evyTs= X-Received: by 2002:a50:f404:: with SMTP id r4mr800225edm.62.1606959308396; Wed, 02 Dec 2020 17:35:08 -0800 (PST) MIME-Version: 1.0 References: <20201202052330.474592-1-pasha.tatashin@soleen.com> <20201202052330.474592-7-pasha.tatashin@soleen.com> <20201202163507.GL5487@ziepe.ca> <20201203010809.GQ5487@ziepe.ca> In-Reply-To: <20201203010809.GQ5487@ziepe.ca> From: Pavel Tatashin Date: Wed, 2 Dec 2020 20:34:32 -0500 Message-ID: Subject: Re: [PATCH 6/6] mm/gup: migrate pinned pages out of movable zone To: Jason Gunthorpe Cc: LKML , linux-mm , Andrew Morton , Vlastimil Babka , Michal Hocko , David Hildenbrand , Oscar Salvador , Dan Williams , Sasha Levin , Tyler Hicks , Joonsoo Kim , mike.kravetz@oracle.com, Steven Rostedt , Ingo Molnar , Peter Zijlstra , Mel Gorman , Matthew Wilcox , David Rientjes , John Hubbard Content-Type: text/plain; charset="UTF-8" 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, Dec 2, 2020 at 8:08 PM Jason Gunthorpe wrote: > > On Wed, Dec 02, 2020 at 07:19:45PM -0500, Pavel Tatashin wrote: > > > It is a good moment to say, I really dislike how this was implemented > > > in the first place. > > > > > > Scanning the output of gup just to do the is_migrate_movable() test is > > > kind of nonsense and slow. It would be better/faster to handle this > > > directly while gup is scanning the page tables and adding pages to the > > > list. > > > > Hi Jason, > > > > I assume you mean to migrate pages as soon as they are followed and > > skip those that are faulted, as we already know that faulted pages are > > allocated from nomovable zone. > > > > The place would be: > > > > __get_user_pages() > > while(more pages) > > get_gate_page() > > follow_hugetlb_page() > > follow_page_mask() > > > > if (!page) > > faultin_page() > > > > if (page && !faulted && (gup_flags & FOLL_LONGTERM) ) > > check_and_migrate this page > > Either here or perhaps even lower down the call chain when the page is > captured, similar to how GUP fast would detect it. (how is that done > anyhow?) Ah, thank you for pointing this out. I think I need to address it here: https://soleen.com/source/xref/linux/mm/gup.c?r=96e1fac1#94 static __maybe_unused struct page *try_grab_compound_head() if (unlikely(flags & FOLL_LONGTERM) && is_migrate_cma_page(page)) return NULL; I need to change is_migrate_cma_page() to all migratable pages. Will study, and send an update with this fix. > > > I looked at that function, and I do not think the code will be cleaner > > there, as that function already has a complicated loop. > > That function is complicated for its own reasons.. But complicated is > not the point here.. > > > The only drawback with the current approach that I see is that > > check_and_migrate_movable_pages() has to check once the faulted > > pages. > > Yes > > > This is while not optimal is not horrible. > > It is. > > > The FOLL_LONGTERM should not happen too frequently, so having one > > extra nr_pages loop should not hurt the performance. > > FOLL_LONGTERM is typically used with very large regions, for instance > we are benchmarking around the 300G level. It takes 10s of seconds for > get_user_pages to operate. There are many inefficiencies in this > path. This extra work of re-scanning the list is part of the cost. OK, I did not realize that pinning was for such large regions, the path must be optimized. > > Further, having these special wrappers just for FOLL_LONGTERM has a > spill over complexity on the entire rest of the callchain up to here, > we now have endless wrappers and varieties of function calls that > generally are happening because the longterm path needs to end up in a > different place than other paths. > > IMHO this is due to the lack of integration with the primary loop > above > > > Also, I checked and most of the users of FOLL_LONGTERM pin only one > > page at a time. Which means the extra loop is only to check a single > > page. > > Er, I don't know what you checked but those are not the cases I > see. Two big users are vfio and rdma. Both are pinning huge ranges of > memory in very typical use cases. What I meant is the users of the interface do it incrementally not in large chunks. For example: vfio_pin_pages_remote vaddr_get_pfn ret = pin_user_pages_remote(mm, vaddr, 1, flags | FOLL_LONGTERM, page, NULL, NULL); 1 -> pin only one pages at a time RDMA indeed can do it in one chunk though. Regardless, the VFIO should probably be optimized to do it in a larger chunk, and the code path should be optimized for the reasons you gave above. > > > However, those changes can come after this series. The current series > > fixes a bug where hot-remove is not working with making minimal amount > > of changes, so it is easy to backport it to stable kernels. > > This is a good point, good enough that you should probably continue as > is I will continue looking into this code, and see if I can address your concerns in a follow-up fixes. Thanks, Pasha > > Jason