Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp1513500rwb; Tue, 27 Sep 2022 14:24:35 -0700 (PDT) X-Google-Smtp-Source: AMsMyM54MOT3OL6KW3c2vz+PitlKkUaEQ6TKWBeQ9KXJhdDY72dLK5HW3laOH5DUOVpxdcI6GO4L X-Received: by 2002:a17:902:a383:b0:176:dd41:4f56 with SMTP id x3-20020a170902a38300b00176dd414f56mr28727744pla.104.1664313874946; Tue, 27 Sep 2022 14:24:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664313874; cv=none; d=google.com; s=arc-20160816; b=Wea7nkfQ9ylfAA+obxF11GjMbU2Jgohxo6laQj5t/2GwxxX2+xu+d3k72S4mHFZZ/j BGPyXEP1UUoC3Por2pASQzda1TWKi3+XtZKYWHml5hRHuNJA8VV37WMMAF5y0xfSIXG/ S92jUHtiEkcBUnYihFwFzi9ULnoPVW6B0VmrUn1vDu1jxsN8An6ZVDNlFoFKzwEt/3iO KNbfrddyYynozyKM4hPsEwa2OlkU/m0Xi8cZ8QCrE+jSzeuK0IpSjPB6rl8UDOLLlkUe 5bwE7ZOXgSSjREM8GRq/wIHMP2SFEqXgigy+g7HwOWYv0US/rt4+rk2EW6MnW1+zre0B jItQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=JhFaXT/LTm6dJIMFtmVs4nNn7X53gVvoLeA/cKj/Kok=; b=CIRVkqA6lCu7kLD6sTsQw84O6VYpG06oofLEDNaWKV/TMc67B7ABePCTSaCdhwSdh6 lUmQZv9FX0eUXCKDC3DU2RCXf8jqS1gv6FKAsOaLkwHvAr5GUqC3BDNSAT5LrIcuEDlN yctvqET5nXCHWUBlpZW7IVI7skQqsOtPCy6xEqw8x1cNBB5OSVX6DrpmF4AcD2CO5yBc yLxWCwD4X4W3f0qjJXH+TX3D9qmbsxZaEfgLwlA0YoMziH74LkKHBY16vtJBrkTFrG/k EX9WbQMpLpFcK3J7q9yZqtZ9biQpHVskbUm/14lDI37aCxb/I4lkR9mfPdxXkqTrCaMq j98g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="WbxQz3//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id lb8-20020a17090b4a4800b0020055731860si3591587pjb.105.2022.09.27.14.24.23; Tue, 27 Sep 2022 14:24:34 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b="WbxQz3//"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S231816AbiI0U4U (ORCPT + 99 others); Tue, 27 Sep 2022 16:56:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56548 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229950AbiI0U4S (ORCPT ); Tue, 27 Sep 2022 16:56:18 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3687E10D643 for ; Tue, 27 Sep 2022 13:56:18 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id bu5-20020a17090aee4500b00202e9ca2182so2235315pjb.0 for ; Tue, 27 Sep 2022 13:56:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date; bh=JhFaXT/LTm6dJIMFtmVs4nNn7X53gVvoLeA/cKj/Kok=; b=WbxQz3//FCAeiZv7aNflDd8o/IexLIOZYI6UqFZ46vdzRXqmqckoy5VF84QOTdmG6W Amaf6YGuhyuPAUHuzFXEAC1iCjeP9Gy7Hf6ackzi88O/pYboc6aZvxP+/0HYZPnSrGb2 BiAXB8EFN9XDhDYpOPiwwqBdZO8gyja5ReQFjim8JO2Dz/YZK2jkxK0qfQ9M3BDm+dFp cBUzmBuNJxE91ZcD7w5r1d3+11RpJx3m/YT8R9yTahMG9yP1kvDxVaqN8+Je02Ren2Qw xSqh1qggygHKpMUBVOAN29FtO0nSTnyc2scJkPNIBaktSPDMNPW/5HSh+zf3NIVMw3yd Cx9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date; bh=JhFaXT/LTm6dJIMFtmVs4nNn7X53gVvoLeA/cKj/Kok=; b=vI6AwWI/JGiqZMkMNO6Fub/1b+Vn9X/G2ulRhNMhWkmKbR26BkovUhkgIukK2bmsY2 rDFimdkFhHi2LDYyaRwqw49I5IvVM99aDQ07i0CyqOhyqdeNd3Ob1i7OsjbWPPdHYhiH J3qw3jEFW5oFe9fmJ1nfLIMdzsThlaoj6KYtve6l/XymrHBWfVHixfrz28MvoghF2T+m j+bvHNE0YFvgDerP8xA7b8eIGjy4XkHzkksIup9mlCtsj5gAsbefkavMTAp2Va/OvKck bP2EsNdSPYZTSijjzzvfSn0l6MPtF2aXpEK2puGFdorqsvZkpguIdo2qAat+sAoXNo/j iyXQ== X-Gm-Message-State: ACrzQf14bozvIvj1f0wn1jC5DKPiNgIe0uWRfbc1NNmDJQi64Bj5UfUU bo/iVrbUAvJzVgIMhgbpHnNUQesAkQMc7x+2Le4= X-Received: by 2002:a17:903:41c8:b0:177:e7e1:4f4f with SMTP id u8-20020a17090341c800b00177e7e14f4fmr28230270ple.61.1664312177758; Tue, 27 Sep 2022 13:56:17 -0700 (PDT) MIME-Version: 1.0 References: <20220921060616.73086-1-ying.huang@intel.com> <20220921060616.73086-3-ying.huang@intel.com> <87o7v2lbn4.fsf@nvdebian.thelocal> <87fsgdllmb.fsf@nvdebian.thelocal> <87ill937qe.fsf@yhuang6-desk2.ccr.corp.intel.com> In-Reply-To: <87ill937qe.fsf@yhuang6-desk2.ccr.corp.intel.com> From: Yang Shi Date: Tue, 27 Sep 2022 13:56:05 -0700 Message-ID: Subject: Re: [RFC 2/6] mm/migrate_pages: split unmap_and_move() to _unmap() and _move() To: "Huang, Ying" Cc: Alistair Popple , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrew Morton , Zi Yan , Baolin Wang , Oscar Salvador , Matthew Wilcox Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Sep 26, 2022 at 6:52 PM Huang, Ying wrote: > > Alistair Popple writes: > > > Yang Shi writes: > > > >> On Mon, Sep 26, 2022 at 2:37 AM Alistair Popple wrote: > >>> > >>> > >>> Huang Ying writes: > >>> > >>> > This is a preparation patch to batch the page unmapping and moving > >>> > for the normal pages and THP. > >>> > > >>> > In this patch, unmap_and_move() is split to migrate_page_unmap() and > >>> > migrate_page_move(). So, we can batch _unmap() and _move() in > >>> > different loops later. To pass some information between unmap and > >>> > move, the original unused newpage->mapping and newpage->private are > >>> > used. > >>> > >>> This looks like it could cause a deadlock between two threads migrating > >>> the same pages if force == true && mode != MIGRATE_ASYNC as > >>> migrate_page_unmap() will call lock_page() while holding the lock on > >>> other pages in the list. Therefore the two threads could deadlock if the > >>> pages are in a different order. > >> > >> It seems unlikely to me since the page has to be isolated from lru > >> before migration. The isolating from lru is atomic, so the two threads > >> unlikely see the same pages on both lists. > > > > Oh thanks! That is a good point and I agree since lru isolation is > > atomic the two threads won't see the same pages. migrate_vma_setup() > > does LRU isolation after locking the page which is why the potential > > exists there. We could potentially switch that around but given > > ZONE_DEVICE pages aren't on an lru it wouldn't help much. > > > >> But there might be other cases which may incur deadlock, for example, > >> filesystem writeback IIUC. Some filesystems may lock a bunch of pages > >> then write them back in a batch. The same pages may be on the > >> migration list and they are also dirty and seen by writeback. I'm not > >> sure whether I miss something that could prevent such a deadlock from > >> happening. > > > > I'm not overly familiar with that area but I would assume any filesystem > > code doing this would already have to deal with deadlock potential. > > Thank you very much for pointing this out. I think the deadlock is a > real issue. Anyway, we shouldn't forbid other places in kernel to lock > 2 pages at the same time. > > The simplest solution is to batch page migration only if mode == > MIGRATE_ASYNC. Then we may consider to fall back to non-batch mode if > mode != MIGRATE_ASYNC and trylock page fails. Seems like so... > > Best Regards, > Huang, Ying > > [snip]