From patchwork Wed Jul 25 06:37:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "zhaowuyun@wingtech.com" X-Patchwork-Id: 10543491 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9579C1822 for ; Wed, 25 Jul 2018 06:38:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7BC65292EB for ; Wed, 25 Jul 2018 06:38:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6CAFD292F6; Wed, 25 Jul 2018 06:38:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-1.2 required=2.0 tests=BAYES_00,HTML_MESSAGE, MAILING_LIST_MULTI,MIME_BASE64_TEXT,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3547D292EB for ; Wed, 25 Jul 2018 06:38:44 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 135E96B0266; Wed, 25 Jul 2018 02:38:43 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0E44A6B0269; Wed, 25 Jul 2018 02:38:43 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id F3C776B026B; Wed, 25 Jul 2018 02:38:42 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-io0-f200.google.com (mail-io0-f200.google.com [209.85.223.200]) by kanga.kvack.org (Postfix) with ESMTP id CC5E96B0266 for ; Wed, 25 Jul 2018 02:38:42 -0400 (EDT) Received: by mail-io0-f200.google.com with SMTP id t11-v6so4376208iog.15 for ; Tue, 24 Jul 2018 23:38:42 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-original-authentication-results:x-gm-message-state:date:from:to :cc:subject:mime-version:message-id; bh=B1puYkdIx7EFoZifYnkOvfiCMDWBIeRU2rbifxmbTjw=; b=DJgY/Jk2nMD3GvGg3Ha2MBgW5ZsG3FGLrfsoO3/Ilq6WMqRJcJD9fN1U3ODDbvsRxZ L5ZcUxqHQkkeYqoh4M9yt95w0GvviQ3DLPMg5VFysGtFElg5/DFZRufGHiGG2SzsHZac l5EqOV35i2979GtdQZSTkn2LaLdw4zVUOtKkuzdyKjoS1YnIxWYxYO1DSc04Q5vDfOW2 HgpZBUxy6ZZ8adbeVasc8TCGYy7MlhN3Wsf391JS8ojMmAVXn3HLqMdcwDPfIM/jgBXj afUY/fuk5qfUSEQQs9BfYgmj3q8b3A5IKSwkbzKEBfXk7Mt2XkcKk9+nG4SFSkzR3VvT ACPg== X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of zhaowuyun@wingtech.com designates 180.166.216.14 as permitted sender) smtp.mailfrom=zhaowuyun@wingtech.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wingtech.com X-Gm-Message-State: AOUpUlEMkfb5VA7EbkJGmNxTSnzQoCtvZCimGUCoSzxuywQeMADdM4ir j6KocPG3xuM1lgdgLP+OjhLZ07noKvvoi4u5cCMXSZj682S+PG1vflfh8W5TWeMG85/DmGwnseT 2CcC5+W18qSE+qRsi/3XxmmolqPGDW0AGXH3e79dypedyB3G4b3pct7BzMwKEuzqHYg== X-Received: by 2002:a24:d9d6:: with SMTP id p205-v6mr4873175itg.89.1532500722603; Tue, 24 Jul 2018 23:38:42 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcTtEuOE6Bk2GXiOYKbV1VisdlYVODr/iswl/Pgwxs3JXRh1vnxGBIlJYNkV67OL8rr18lN X-Received: by 2002:a24:d9d6:: with SMTP id p205-v6mr4873154itg.89.1532500721754; Tue, 24 Jul 2018 23:38:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532500721; cv=none; d=google.com; s=arc-20160816; b=aS2kxtkpnI6QHfqxoI0O+nNlWCfplPZ/kF+cYfXfq5bwUsePJa0uXAEX4B94sg5eK2 BqpiHm9ckYBP1jJDnkwrH7H9+Q4simhVtjQ+po66Lvm6Za73/zrG2zyW4E318wYf1F9j RFBYjhUW8+CLwW7SlurrqdUFsEYWkW65nXOyTjluojWexAWHXeh5abXHnEl0v5aD7fai 4SFKYx785WKcwxYAafIPOsDFThPQsr1ZSxW5Oj6N1xEpbHJs8ggetxOxbP/oZhsM8KEb Onu+SUXDsKnOUZzCBTVDcJH+ztxYYi7095j6O/lFkq3oc7xpo5O4V0rAGqNtBNXPnmI4 ccRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=message-id:mime-version:subject:cc:to:from:date :arc-authentication-results; bh=B1puYkdIx7EFoZifYnkOvfiCMDWBIeRU2rbifxmbTjw=; b=TdpT0/kGtGSOq2ylh9Fk2cF4FmAWkG6IvEDQ8cmZXTe3FKchN0KpQmGKHy3r2CtaKH OvP//9ATDkhuJgFpvyYhsyPCoVMFetMxAt1y3P1rzCLqQNGINLmtHHBox1uVcD7XQdE9 IB2h+JFg30N884kH83HfJtCxSxBfY8yQRiH34kHkcJbsyw/CZfI29pWwO7utINASvb/3 vAJ4lSggp7dBULabjEEGoYcjXYibrCI21O8AnKMRUSMfbUKOsP9ZISx8TxVJghYykeX3 ZhZEvXIVvJl9u+KVN+D+WmMlznsei0GtW6IqJ81a+0DRhpkM9baIQBwgmaZsSJ5uXZO2 kbrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of zhaowuyun@wingtech.com designates 180.166.216.14 as permitted sender) smtp.mailfrom=zhaowuyun@wingtech.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wingtech.com Received: from mail.wingtech.com (mail.wingtech.com. [180.166.216.14]) by mx.google.com with ESMTPS id d129-v6si2838518itc.67.2018.07.24.23.38.40 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 24 Jul 2018 23:38:41 -0700 (PDT) Received-SPF: pass (google.com: domain of zhaowuyun@wingtech.com designates 180.166.216.14 as permitted sender) client-ip=180.166.216.14; Authentication-Results: mx.google.com; spf=pass (google.com: domain of zhaowuyun@wingtech.com designates 180.166.216.14 as permitted sender) smtp.mailfrom=zhaowuyun@wingtech.com; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=wingtech.com Received: from zhaowuyun10 ([192.168.51.70]) (user=zhaowuyun@wingtech.com mech=LOGIN bits=0) by mail.wingtech.com with ESMTP id w6P6bwCL026997-w6P6bwCM026997; Wed, 25 Jul 2018 14:37:58 +0800 Date: Wed, 25 Jul 2018 14:37:58 +0800 From: "zhaowuyun@wingtech.com" To: mgorman , akpm , minchan Cc: vinmenon , mhocko , hannes , hillf.zj , linux-mm , linux-kernel Subject: [PATCH] [PATCH] mm: disable preemption before swapcache_free X-Priority: 3 X-Has-Attach: no X-Mailer: Foxmail 7.2.9.116[cn] Mime-Version: 1.0 Message-ID: <2018072514375722198958@wingtech.com> X-FEAS-AUTH-USER: zhaowuyun@wingtech.com 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: X-Virus-Scanned: ClamAV using ClamSMTP From: zhaowuyun issue is that there are two processes A and B, A is kworker/u16:8 normal priority, B is AudioTrack, RT priority, they are on the same CPU 3. The task A preempted by task B in the moment after __delete_from_swap_cache(page) and before swapcache_free(swap). The task B does __read_swap_cache_async in the do {} while loop, it will never find the page from swapper_space because the page is removed by the task A, and it will never sucessfully in swapcache_prepare because the entry is EEXIST. The task B then stuck in the loop infinitely because it is a RT task, no one can preempt it. so need to disable preemption until the swapcache_free executed. TASK A: __delete_from_swap_cache(page); spin_unlock_irqrestore(&mapping->tree_lock, flags); swapcache_free(swap); + preempt_enable(); } else { void (*freepage)(struct page *); void *shadow = NULL; @@ -740,6 +747,7 @@ static int __remove_mapping(struct address_space *mapping, struct page *page, shadow = workingset_eviction(mapping, page); __delete_from_page_cache(page, shadow); spin_unlock_irqrestore(&mapping->tree_lock, flags); + preempt_enable(); if (freepage != NULL) freepage(page); @@ -749,6 +757,7 @@ static int __remove_mapping(struct address_space *mapping, struct page *page, cannot_free: spin_unlock_irqrestore(&mapping->tree_lock, flags); + preempt_enable(); return 0; } ===================================================== Process: kworker/u16:8, cpu: 3 pid: 20289 start: 0xffffffc0385f8e00 ===================================================== Task name: kworker/u16:8 pid: 20289 cpu: 3 start: ffffffc0385f8e00 state: 0x0 exit_state: 0x0 stack base: 0xffffffc012ba0000 Prio: 120 Stack: [] __switch_to+0x90 [] __schedule+0x29c [] preempt_schedule_common+0x24 [] preempt_schedule.part.169+0x1c [] preempt_schedule+0x20 [] _raw_spin_unlock_irqrestore+0x40 [] __remove_mapping+0x174 [] shrink_page_list+0x894 [] reclaim_pages_from_list+0xc8 [] reclaim_pte_range+0x158 [] walk_pgd_range+0xd4 [] walk_page_range+0x74 [] reclaim_task_anon+0xdc [] swap_fn+0x1b8 [] process_one_work+0x168 [] worker_thread+0x224 [] kthread+0xe0 [] ret_from_fork+0x10 TASK B: [535478.724249] CPU: 3 PID: 4645 Comm: AudioTrack Tainted: GF UD W O 4.9.82-perf+ #1 [535478.724385] Hardware name: Qualcomm Technologies, Inc. SDM450 PMI632 MTP S3 (DT) [535478.724479] task: ffffffc026ce2a00 task.stack: ffffffc012e14000 [535478.724537] PC is at __read_swap_cache_async+0x154/0x25c [535478.724630] LR is at __read_swap_cache_async+0x9c/0x25c ... [535478.735546] [] __read_swap_cache_async+0x154/0x25c [535478.735599] [] read_swap_cache_async+0x20/0x54 [535478.735697] [] swapin_readahead+0x58/0x218 [535478.735797] [] do_swap_page+0x3c4/0x4d0 [535478.735850] [] handle_mm_fault+0x364/0xba4 [535478.735949] [] do_page_fault+0x2a0/0x38c [535478.736003] [] do_translation_fault+0x40/0x48 [535478.736100] [] do_mem_abort+0x50/0xc8 Change-Id: I36d9df7ccff77c589b7157225410269c675a8504 Signed-off-by: zhaowuyun --- mm/vmscan.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/vmscan.c b/mm/vmscan.c index 2740973..acede002 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -674,6 +674,12 @@ static int __remove_mapping(struct address_space *mapping, struct page *page, BUG_ON(!PageLocked(page)); BUG_ON(mapping != page_mapping(page)); + /* + * preemption must be disabled to protect current task preempted before + * swapcache_free(swap) invoked by the task which do the + * __read_swap_cache_async job on the same page + */ + preempt_disable(); spin_lock_irqsave(&mapping->tree_lock, flags); /* * The non racy check for a busy page. @@ -714,6 +720,7 @@ static int __remove_mapping(struct address_space *mapping, struct page *page,