“My son” tell us who this message is to. It is not to the world in general, but to the followers of God. God reminds us to not forget His teachings but hide them away in our hearts. God also reminds us to walk in His ways.
His “commandments” here are talking about all of His ways. Just as the commandment to honor father and mother promises that our days may be long upon the earth, we see the promises of length of days here if we follow in His ways.
When you know that you have done the right things, it does bring peace. Sin brings fear of punishment, but obedience brings peace.