@@ -23,6 +23,7 @@ use tempfile::TempDir;
23
23
24
24
use crate :: CgroupReader ;
25
25
use crate :: Error ;
26
+ use crate :: MemoryNumaStat ;
26
27
27
28
struct TestCgroup {
28
29
tempdir : TempDir ,
@@ -620,3 +621,190 @@ fn test_cgroup_stat_invalid_format() {
620
621
_ => panic ! ( "Got unexpected error type: {}" , err) ,
621
622
}
622
623
}
624
+
625
+ #[ test]
626
+ fn test_memory_numa_stat_success ( ) {
627
+ let cgroup = TestCgroup :: new ( ) ;
628
+ cgroup. create_file_with_content (
629
+ "memory.numa_stat" ,
630
+ b"anon N0=133948178432 N1=85731622912 N2=56469581824 N3=67508137984
631
+ file N0=29022474240 N1=28619689984 N2=27863502848 N3=20205821952
632
+ kernel_stack N0=139689984 N1=93978624 N2=104693760 N3=145391616
633
+ pagetables N0=464572416 N1=392798208 N2=332378112 N3=352788480
634
+ shmem N0=27244945408 N1=27178311680 N2=27170930688 N3=13595549696
635
+ file_mapped N0=27685949440 N1=27733299200 N2=27522891776 N3=15582023680
636
+ file_dirty N0=6488064 N1=17436672 N2=85155840 N3=165040128
637
+ file_writeback N0=0 N1=0 N2=38522880 N3=123408384
638
+ swapcached N0=0 N1=0 N2=0 N3=0
639
+ anon_thp N0=1419771904 N1=673185792 N2=536870912 N3=681574400
640
+ file_thp N0=48234496 N1=14680064 N2=0 N3=48234496
641
+ shmem_thp N0=48234496 N1=8388608 N2=0 N3=8388608
642
+ inactive_anon N0=160479961088 N1=112294313984 N2=83386806272 N3=80141840384
643
+ active_anon N0=466096128 N1=398712832 N2=8605696 N3=599347200
644
+ inactive_file N0=1189363712 N1=913510400 N2=448503808 N3=2159505408
645
+ active_file N0=522350592 N1=460431360 N2=206303232 N3=4300206080
646
+ unevictable N0=405504 N1=135168 N2=0 N3=0
647
+ slab_reclaimable N0=663340528 N1=563089336 N2=514239048 N3=647222000
648
+ slab_unreclaimable N0=686272088 N1=472630728 N2=556250640 N3=693263576
649
+ workingset_refault_anon N0=3497864 N1=2225803 N2=2410565 N3=1468001
650
+ workingset_refault_file N0=214724399 N1=172943243 N2=2094241456 N3=155295239
651
+ workingset_activate_anon N0=477507 N1=238415 N2=318245 N3=235467
652
+ workingset_activate_file N0=96231899 N1=75825820 N2=674636976 N3=61718859
653
+ workingset_restore_anon N0=182593 N1=55793 N2=96984 N3=53780
654
+ workingset_restore_file N0=74008297 N1=63719159 N2=528595708 N3=48463497
655
+ workingset_nodereclaim N0=266941 N1=176289 N2=1260264 N3=638641" ,
656
+ ) ;
657
+
658
+ let cgroup_reader = cgroup. get_reader ( ) ;
659
+ let val = cgroup_reader
660
+ . read_memory_numa_stat ( )
661
+ . expect ( "Failed to read numa memory stat" ) ;
662
+
663
+ assert_eq ! ( val. len( ) , 4 ) ;
664
+ let node0 = MemoryNumaStat {
665
+ anon : Some ( 133948178432 ) ,
666
+ file : Some ( 29022474240 ) ,
667
+ kernel_stack : Some ( 139689984 ) ,
668
+ pagetables : Some ( 464572416 ) ,
669
+ shmem : Some ( 27244945408 ) ,
670
+ file_mapped : Some ( 27685949440 ) ,
671
+ file_dirty : Some ( 6488064 ) ,
672
+ file_writeback : Some ( 0 ) ,
673
+ swapcached : Some ( 0 ) ,
674
+ anon_thp : Some ( 1419771904 ) ,
675
+ file_thp : Some ( 48234496 ) ,
676
+ shmem_thp : Some ( 48234496 ) ,
677
+ inactive_anon : Some ( 160479961088 ) ,
678
+ active_anon : Some ( 466096128 ) ,
679
+ inactive_file : Some ( 1189363712 ) ,
680
+ active_file : Some ( 522350592 ) ,
681
+ unevictable : Some ( 405504 ) ,
682
+ slab_reclaimable : Some ( 663340528 ) ,
683
+ slab_unreclaimable : Some ( 686272088 ) ,
684
+ workingset_refault_anon : Some ( 3497864 ) ,
685
+ workingset_refault_file : Some ( 214724399 ) ,
686
+ workingset_activate_anon : Some ( 477507 ) ,
687
+ workingset_activate_file : Some ( 96231899 ) ,
688
+ workingset_restore_anon : Some ( 182593 ) ,
689
+ workingset_restore_file : Some ( 74008297 ) ,
690
+ workingset_nodereclaim : Some ( 266941 ) ,
691
+ } ;
692
+ let node1 = MemoryNumaStat {
693
+ anon : Some ( 85731622912 ) ,
694
+ file : Some ( 28619689984 ) ,
695
+ kernel_stack : Some ( 93978624 ) ,
696
+ pagetables : Some ( 392798208 ) ,
697
+ shmem : Some ( 27178311680 ) ,
698
+ file_mapped : Some ( 27733299200 ) ,
699
+ file_dirty : Some ( 17436672 ) ,
700
+ file_writeback : Some ( 0 ) ,
701
+ swapcached : Some ( 0 ) ,
702
+ anon_thp : Some ( 673185792 ) ,
703
+ file_thp : Some ( 14680064 ) ,
704
+ shmem_thp : Some ( 8388608 ) ,
705
+ inactive_anon : Some ( 112294313984 ) ,
706
+ active_anon : Some ( 398712832 ) ,
707
+ inactive_file : Some ( 913510400 ) ,
708
+ active_file : Some ( 460431360 ) ,
709
+ unevictable : Some ( 135168 ) ,
710
+ slab_reclaimable : Some ( 563089336 ) ,
711
+ slab_unreclaimable : Some ( 472630728 ) ,
712
+ workingset_refault_anon : Some ( 2225803 ) ,
713
+ workingset_refault_file : Some ( 172943243 ) ,
714
+ workingset_activate_anon : Some ( 238415 ) ,
715
+ workingset_activate_file : Some ( 75825820 ) ,
716
+ workingset_restore_anon : Some ( 55793 ) ,
717
+ workingset_restore_file : Some ( 63719159 ) ,
718
+ workingset_nodereclaim : Some ( 176289 ) ,
719
+ } ;
720
+ let node2 = MemoryNumaStat {
721
+ anon : Some ( 56469581824 ) ,
722
+ file : Some ( 27863502848 ) ,
723
+ kernel_stack : Some ( 104693760 ) ,
724
+ pagetables : Some ( 332378112 ) ,
725
+ shmem : Some ( 27170930688 ) ,
726
+ file_mapped : Some ( 27522891776 ) ,
727
+ file_dirty : Some ( 85155840 ) ,
728
+ file_writeback : Some ( 38522880 ) ,
729
+ swapcached : Some ( 0 ) ,
730
+ anon_thp : Some ( 536870912 ) ,
731
+ file_thp : Some ( 0 ) ,
732
+ shmem_thp : Some ( 0 ) ,
733
+ inactive_anon : Some ( 83386806272 ) ,
734
+ active_anon : Some ( 8605696 ) ,
735
+ inactive_file : Some ( 448503808 ) ,
736
+ active_file : Some ( 206303232 ) ,
737
+ unevictable : Some ( 0 ) ,
738
+ slab_reclaimable : Some ( 514239048 ) ,
739
+ slab_unreclaimable : Some ( 556250640 ) ,
740
+ workingset_refault_anon : Some ( 2410565 ) ,
741
+ workingset_refault_file : Some ( 2094241456 ) ,
742
+ workingset_activate_anon : Some ( 318245 ) ,
743
+ workingset_activate_file : Some ( 674636976 ) ,
744
+ workingset_restore_anon : Some ( 96984 ) ,
745
+ workingset_restore_file : Some ( 528595708 ) ,
746
+ workingset_nodereclaim : Some ( 1260264 ) ,
747
+ } ;
748
+ let node3 = MemoryNumaStat {
749
+ anon : Some ( 67508137984 ) ,
750
+ file : Some ( 20205821952 ) ,
751
+ kernel_stack : Some ( 145391616 ) ,
752
+ pagetables : Some ( 352788480 ) ,
753
+ shmem : Some ( 13595549696 ) ,
754
+ file_mapped : Some ( 15582023680 ) ,
755
+ file_dirty : Some ( 165040128 ) ,
756
+ file_writeback : Some ( 123408384 ) ,
757
+ swapcached : Some ( 0 ) ,
758
+ anon_thp : Some ( 681574400 ) ,
759
+ file_thp : Some ( 48234496 ) ,
760
+ shmem_thp : Some ( 8388608 ) ,
761
+ inactive_anon : Some ( 80141840384 ) ,
762
+ active_anon : Some ( 599347200 ) ,
763
+ inactive_file : Some ( 2159505408 ) ,
764
+ active_file : Some ( 4300206080 ) ,
765
+ unevictable : Some ( 0 ) ,
766
+ slab_reclaimable : Some ( 647222000 ) ,
767
+ slab_unreclaimable : Some ( 693263576 ) ,
768
+ workingset_refault_anon : Some ( 1468001 ) ,
769
+ workingset_refault_file : Some ( 155295239 ) ,
770
+ workingset_activate_anon : Some ( 235467 ) ,
771
+ workingset_activate_file : Some ( 61718859 ) ,
772
+ workingset_restore_anon : Some ( 53780 ) ,
773
+ workingset_restore_file : Some ( 48463497 ) ,
774
+ workingset_nodereclaim : Some ( 638641 ) ,
775
+ } ;
776
+ assert_eq ! ( val[ & 0 ] , node0) ;
777
+ assert_eq ! ( val[ & 1 ] , node1) ;
778
+ assert_eq ! ( val[ & 2 ] , node2) ;
779
+ assert_eq ! ( val[ & 3 ] , node3) ;
780
+ }
781
+
782
+ #[ test]
783
+ fn test_memory_numa_stat_parse_failure ( ) {
784
+ let cgroup = TestCgroup :: new ( ) ;
785
+ cgroup. create_file_with_content ( "memory.numa_stat" , b"anon garbage\n file garbage" ) ;
786
+
787
+ let cgroup_reader = cgroup. get_reader ( ) ;
788
+ let err = cgroup_reader
789
+ . read_memory_numa_stat ( )
790
+ . expect_err ( "Did not fail to read memory.numa.stat" ) ;
791
+ match err {
792
+ Error :: UnexpectedLine ( _, _) => { }
793
+ _ => panic ! ( "Got unexpected error type {}" , err) ,
794
+ }
795
+ }
796
+
797
+ #[ test]
798
+ fn test_memory_numa_stat_invalid_format ( ) {
799
+ let cgroup = TestCgroup :: new ( ) ;
800
+ cgroup. create_file_with_content ( "memory.numa_stat" , b"" ) ;
801
+
802
+ let cgroup_reader = cgroup. get_reader ( ) ;
803
+ let err = cgroup_reader
804
+ . read_memory_numa_stat ( )
805
+ . expect_err ( "Did not fail to read memory.numa_stat" ) ;
806
+ match err {
807
+ Error :: InvalidFileFormat ( _) => { }
808
+ _ => panic ! ( "Got unexpected error type: {}" , err) ,
809
+ }
810
+ }
0 commit comments