| 771 | } |
| 772 | |
| 773 | void BufferPoolTest::TestCleanPageLimit(int max_clean_pages, bool randomize_core) { |
| 774 | const int MAX_NUM_BUFFERS = 4; |
| 775 | const int64_t TOTAL_MEM = MAX_NUM_BUFFERS * TEST_BUFFER_LEN; |
| 776 | const int max_clean_page_bytes = max_clean_pages * TEST_BUFFER_LEN; |
| 777 | global_reservations_.InitRootTracker(NewProfile(), TOTAL_MEM); |
| 778 | MetricGroup tmp_metrics("test-metrics"); |
| 779 | BufferPool pool(&tmp_metrics, TEST_BUFFER_LEN, TOTAL_MEM, max_clean_page_bytes); |
| 780 | |
| 781 | ClientHandle client; |
| 782 | ASSERT_OK(pool.RegisterClient("test client", NewFileGroup(), &global_reservations_, |
| 783 | nullptr, TOTAL_MEM, NewProfile(), &client)); |
| 784 | ASSERT_TRUE(client.IncreaseReservation(TOTAL_MEM)); |
| 785 | if (!randomize_core) CpuTestUtil::PinToCore(0); |
| 786 | vector<PageHandle> pages; |
| 787 | CreatePages(&pool, &client, TEST_BUFFER_LEN, TOTAL_MEM, &pages, randomize_core); |
| 788 | WriteData(pages, 0); |
| 789 | |
| 790 | // Unpin pages and wait until they're written out and therefore clean. |
| 791 | UnpinAll(&pool, &client, &pages); |
| 792 | WaitForAllWrites(&client); |
| 793 | EXPECT_EQ(max_clean_pages, pool.GetNumCleanPages()); |
| 794 | EXPECT_EQ(max_clean_page_bytes, pool.GetCleanPageBytes()); |
| 795 | |
| 796 | // Do an allocation to force a buffer to be reclaimed from somewhere. |
| 797 | ASSERT_OK(AllocateAndFree(&pool, &client, TEST_BUFFER_LEN)); |
| 798 | if (randomize_core) { |
| 799 | // We will either evict a clean page or reclaim a free buffer, depending on the |
| 800 | // arena that we pick. |
| 801 | EXPECT_LE(pool.GetNumCleanPages(), max_clean_pages); |
| 802 | EXPECT_LE(pool.GetCleanPageBytes(), max_clean_page_bytes); |
| 803 | } else { |
| 804 | // We will reclaim one of the free buffers in arena 0. |
| 805 | EXPECT_EQ(min(MAX_NUM_BUFFERS - 1, max_clean_pages), pool.GetNumCleanPages()); |
| 806 | const int64_t expected_clean_page_bytes = |
| 807 | min<int64_t>((MAX_NUM_BUFFERS - 1) * TEST_BUFFER_LEN, max_clean_page_bytes); |
| 808 | EXPECT_EQ(expected_clean_page_bytes, pool.GetCleanPageBytes()); |
| 809 | } |
| 810 | |
| 811 | // Re-pin all the pages - none will be clean afterwards. |
| 812 | ASSERT_OK(PinAll(&pool, &client, &pages)); |
| 813 | VerifyData(pages, 0); |
| 814 | EXPECT_EQ(0, pool.GetNumCleanPages()); |
| 815 | EXPECT_EQ(0, pool.GetCleanPageBytes()); |
| 816 | |
| 817 | DestroyAll(&pool, &client, &pages); |
| 818 | pool.DeregisterClient(&client); |
| 819 | global_reservations_.Close(); |
| 820 | } |
| 821 | |
| 822 | /// Test transfer of buffer handles between clients. |
| 823 | TEST_F(BufferPoolTest, BufferTransfer) { |
nothing calls this directly
no test coverage detected