From patchwork Tue Sep 18 03:02:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Zhang, Lei" X-Patchwork-Id: 10603675 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 BDEEF5A4 for ; Tue, 18 Sep 2018 03:03:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A55162964E for ; Tue, 18 Sep 2018 03:03:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 958502A6CE; Tue, 18 Sep 2018 03:03:28 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E3BE42964E for ; Tue, 18 Sep 2018 03:03:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=C+rQYsFN6m8wlX9Xu7SOu1yPlW9kF0uzH/Yxatc60tc=; b=bW6P+W5CfdMj49 va727UNhs8jpsggNnCdqICBWP4SB9My8ZJxfKkhIcdIoXdaMi8yEQDxsZVHy4cym1QTnQ7yq3Y7vi fAejkZuUbH38sJ+nBVotWHhHWxljOjG8GySVYDnIU4cFCEwInnqcHXOYJXk6dzBBQy1kDjGj5APFB +xQMZkBsiI97vqXU1h9NCZ4eXqB5o6HQPKukLpaGHoCDw2tunAt5jiZyL0tp6pb3exu6eN1tCmeh8 Pp+8T86E7+np24MGvWkv2YZWirtFeQErxr9LABBjv4Pp/KUtPuFhy+Izp1iWK9KX77f/hSVhXjBMM wg+q7rpu3SEie/3OytKg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g26IC-0000jy-TC; Tue, 18 Sep 2018 03:03:12 +0000 Received: from mgwkm03.jp.fujitsu.com ([202.219.69.170]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g26IA-0000iq-7a for linux-arm-kernel@lists.infradead.org; Tue, 18 Sep 2018 03:03:11 +0000 Received: from kw-mxauth.gw.nic.fujitsu.com (unknown [192.168.231.132]) by mgwkm03.jp.fujitsu.com with smtp id 5b50_ba2d_5f2156d6_d94b_4534_9181_95330f1b8553; Tue, 18 Sep 2018 12:02:49 +0900 Received: from g01jpfmpwkw03.exch.g01.fujitsu.local (g01jpfmpwkw03.exch.g01.fujitsu.local [10.0.193.57]) by kw-mxauth.gw.nic.fujitsu.com (Postfix) with ESMTP id A61BDAC018D for ; Tue, 18 Sep 2018 12:02:40 +0900 (JST) Received: from G01JPEXCHKW15.g01.fujitsu.local (G01JPEXCHKW15.g01.fujitsu.local [10.0.194.54]) by g01jpfmpwkw03.exch.g01.fujitsu.local (Postfix) with ESMTP id 2F774BD6643 for ; Tue, 18 Sep 2018 12:02:18 +0900 (JST) Received: from G01JPEXMBKW03.g01.fujitsu.local ([10.0.194.67]) by g01jpexchkw15 ([10.0.194.54]) with mapi id 14.03.0352.000; Tue, 18 Sep 2018 12:02:17 +0900 From: "Zhang, Lei" To: "linux-arm-kernel@lists.infradead.org" Subject: Huge page(contiguous bit) slow down Thread-Topic: Huge page(contiguous bit) slow down Thread-Index: AdRO/AIT5L/lW3AuSxOc4vJFmnVJFw== Date: Tue, 18 Sep 2018 03:02:17 +0000 Message-ID: <8898674D84E3B24BA3A2D289B872026A69FE8F27@G01JPEXMBKW03> Accept-Language: ja-JP, en-US Content-Language: ja-JP X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [10.128.195.148] MIME-Version: 1.0 X-SecurityPolicyCheck-GC: OK by FENCE-Mail X-TM-AS-MML: disable X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180917_200310_501097_D631E8BE X-CRM114-Status: UNSURE ( 6.73 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP I found a slowdown problem when we uses a huge page on arm64 chip. I think the cause of this problem is a bug of huge_ptep_set_access_flags() with contiguous pte. Could you review and merge my patch? Incident: Multiple threaded process repeats page fault again and again, so the PC in EL0 doesn't move to the next operation. Multiple threads occur page fault at the same time and the same VA. It may cause slowdown or hang of a process. Because a race problem on updating pte maybe happened when the condition matched as below. 1. Multiple threads are running 2. All threads are ld/st-ing to the same huge page 3. The huge page is consist of contiguous ptes (2MiB page = 64KiB page x 32) 4. The huge page is mapped without MAP_POPULATE flag. Mechanism: The mechanism of this problem is as below. Updating pte use 4 steps. step1: create pte content step2: zero-clear pte at ptep_get_and_clear step3: flush tlb at flush_tlb_range step4: set pte at set_pte_at(pte becomes non-zero) When thread1 is doing between step2 and step4, thread2 accesses the same huge page at the same time. It cause a new page fault at thread2. After that, when thread2 is doing between step2 and step4, thread1 retries the access to the same page. It cause a new page fault at thread1 again. Multi-threads repeat this flow again and again. On the other hand, if the pte is not a contiguous pte, slowdown or hang will not occur. Because it check whether a correct pte has been already presented by other thread using pte_same before step2(0 clear pte). Call tree information: hugetlb_fault huge_ptep_set_access_flags ptep_set_access_flags -> ( contiguous pte route not call this) pte_same ptep_get_and_clear flush_tlb_range set_pte_at So our patch calls the same check function not only for non-contiguous pte but also for contiguous pte. ----------------------------- Best Regards Lei Zhang Email: zhang.lei@jp.fujitsu.com FUJTISU LIMITED. --- a/arch/arm64/mm/hugetlbpage.c +++ b/arch/arm64/mm/hugetlbpage.c @@ -332,6 +332,9 @@ int huge_ptep_set_access_flags(struct vm_area_struct *vma, if (!pte_cont(pte)) return ptep_set_access_flags(vma, addr, ptep, pte, dirty); + if(pte_same(pte, READ_ONCE(*ptep))) + return 0; + ncontig = find_num_contig(vma->vm_mm, addr, ptep, &pgsize); dpfn = pgsize >> PAGE_SHIFT;